我在三星健康中遇到以下错误:
04-23 11:42:08.700 15067-15067/com.demo.samsunghealthdemo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.demo.samsunghealthdemo, PID: 15067
java.lang.SecurityException: [INSERT] User permission to WRITE is not acquired
at android.os.Parcel.readException(Parcel.java:1602)
at android.os.Parcel.readException(Parcel.java:1555)
at com.samsung.android.sdk.healthdata.IDataResolver$Stub$a.insertData2(IDataResolver.java:573)
at com.samsung.android.sdk.healthdata.HealthDataResolver.insert(HealthDataResolver.java:321)
at com.demo.samsunghealthdemo.MainActivity.insertWaterData(MainActivity.java:99)
at com.demo.samsunghealthdemo.MainActivity.access$000(MainActivity.java:31)
at com.demo.samsunghealthdemo.MainActivity$1.onClick(MainActivity.java:65)
at android.view.View.performClick(View.java:5264)
at android.view.View$PerformClick.run(View.java:21297)
at android.os.Handler.handleCallback(Handler.java:743)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5546)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
Manifest.xml中的权限
<meta-data
android:name="com.samsung.android.health.permission.read"
android:value="com.samsung.health.food_intake" />
<meta-data
android:name="com.samsung.android.health.permission.write"
android:value="com.samsung.health.food_intake" />
当我尝试从app添加Water Intake时:
HealthDataResolver resolver = new HealthDataResolver(mStore, null);
HealthDataResolver.InsertRequest request = new HealthDataResolver.InsertRequest.Builder().setDataType(HealthConstants.WaterIntake.HEALTH_DATA_TYPE).build();
request.addHealthData(data);
答案 0 :(得分:0)
我认为,您的应用尚未注册为S Health合作伙伴app.So 您需要获得S Health合作伙伴应用认证,然后您的应用将在&#39;白名单&#39; S Health。
出于开发目的,您可以使用S Health的开发模式。
答案 1 :(得分:0)
使用以下解决方法:
private Set<HealthPermissionManager.PermissionKey> generatePermissionKeySet() {
Set<HealthPermissionManager.PermissionKey> pmsKeySet = new HashSet<>();
// Add the read and write permissions to Permission KeySet
pmsKeySet.add(new HealthPermissionManager.PermissionKey(HealthConstants.WaterIntake.HEALTH_DATA_TYPE, HealthPermissionManager.PermissionType.READ));
pmsKeySet.add(new HealthPermissionManager.PermissionKey(HealthConstants.WaterIntake.HEALTH_DATA_TYPE, HealthPermissionManager.PermissionType.WRITE));
return pmsKeySet;
}
And Manifest.xml
<meta-data
android:name="com.samsung.android.health.permission.read"
android:value="com.samsung.health.water_intake" />
<meta-data
android:name="com.samsung.android.health.permission.write"
android:value="com.samsung.health.water_intake" />