I’m making Android Native app with kotlin.
I was check your docs and downloaded API and insert my project.
(location is : ~projectroot/app/libs/samsung-health-data-1.5.0.arr)
And I was add permissions.
<manifest
.....
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY"/>
<uses-permission android:name="com.samsung.android.providers.context.permission.READ_USE_APP_FEATURE_SURVEY"/>
<uses-permission android:name="android.permission.BODY_SENSORS"/>
<!--삼성 SDK-->
<queries>
<package android:name="com.sec.android.app.shealth" />
</queries>
<application
...
<!--삼성 SDK 권한-->
<meta-data
android:name="com.samsung.android.health.permission.read"
android:value="com.samsung.health.step_count;com.samsung.shealth.step_daily_trend" />
......
</manifest>
Add build.gradle too.
/*Samsung sdk*/
implementation files('libs/samsung-health-data-1.5.0.aar')
And request permissions on my MainActivity.
...
private fun initDataStore() {
//권한
mKeySet = HashSet()
mKeySet.add(PermissionKey(Exercise.HEALTH_DATA_TYPE, PermissionType.READ))
mKeySet.add(PermissionKey(Exercise.HEALTH_DATA_TYPE, PermissionType.WRITE))
mKeySet.add(PermissionKey(StepDailyTrend.HEALTH_DATA_TYPE, PermissionType.READ))
mKeySet.add(PermissionKey(HealthConstants.StepCount.HEALTH_DATA_TYPE, PermissionType.READ))
mStore = HealthDataStore(this, mCntListener)
mStore.connectService()
}
...
private val mCntListener: ConnectionListener = object : ConnectionListener {
override fun onConnected() {
Log.d(TAG, "Health data service is connected.")
val mManager = HealthPermissionManager(mStore)
val resultMap : MutableMap<PermissionKey, Boolean> = mManager.isPermissionAcquired(mKeySet)
if(resultMap.containsValue(false)) {
mManager.requestPermissions(mKeySet, this).setResultListener(mPermissionListener)
}
}
....
but every resultMap is false.
And I can see the UI (blowing the image), but I can’t touch the checkbox. (maybe because of resultMAp is false…?)
How can I use the Health API ?