我正在尝试运行这个电话是消费者的示例项目。
http://developer.samsung.com/sample-app/view.do?v=S000000069nCT030000
应用程序使用我的 HTC Desire 820 (4.4.4) 运行良好。
但是,当我在三星 Galaxy S4 (5.0.1) 上运行它时,它会在运行时onCreate()
崩溃ConsumerService
这是我的堆栈跟踪:
FATAL EXCEPTION: main
Process: com.samsung.android.sdk.accessory.example.helloaccessory.consumer, PID: 29617
java.lang.RuntimeException: Unable to create service com.samsung.android.sdk.accessory.example.helloaccessory.consumer.ConsumerService: java.lang.SecurityException: com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY permission is required.
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3167)
at android.app.ActivityThread.access$1900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
Caused by: java.lang.SecurityException: com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY permission is required.
at com.samsung.android.sdk.accessory.SA.initialize(Unknown Source)
at com.samsung.android.sdk.accessory.SAAgent.onCreate(Unknown Source)
at com.samsung.android.sdk.accessory.example.helloaccessory.consumer.ConsumerService.onCreate(ConsumerService.java:52)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3157)
at android.app.ActivityThread.access$1900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1532)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
所以基本上我错过了许可,我使用以下方法确认了这一点:
String permission = "com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY";
int res = getContext().checkCallingOrSelfPermission(permission);
return (res == PackageManager.PERMISSION_GRANTED);
哪个返回false
但是,我在我的 AndroidManifest.xml 中包含了这个权限:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.samsung.android.sdk.accessory.example.helloaccessory.consumer"
android:versionCode="4"
android:versionName="2.0.2" >
<uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="com.samsung.accessory.permission.ACCESSORY_FRAMEWORK" />
<uses-permission android:name="com.samsung.wmanager.ENABLE_NOTIFICATION" />
<uses-permission android:name="com.samsung.WATCH_APP_TYPE.Companion"/>
<application...
我正在使用带有这些版本的 gradle 进行构建:
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.samsung.android.sdk.accessory.example.helloaccessory.consumer"
minSdkVersion 15
targetSdkVersion 23
versionCode 4
versionName '2.0.2'
}
我也在使用
compile 'com.android.support:appcompat-v7:23.1.1'
手机没有root。
有谁知道为什么会发生这种情况以及如何解决这个问题?
谢谢!