我正在开发一个Android应用程序。当我想启动服务时,我遇到了问题:不允许绑定到服务Intent。该服务是Yotaphone后台屏幕服务。
我搜索问题,信息很少,大多数都不是同一类问题。我不知道哪个部分出了问题。
我的指示: http://mwiki.yotaphone.com/wiki/Building_First_App
MainActivity中的onStart()函数:
@Override
protected void onStart() {
super.onStart();
Intent bsIntent = new Intent(this, MyBSActivity.class);
this.startService(bsIntent);
}
Yotaphone后台屏幕服务:
public class MyBSActivity extends BSActivity {
@Override
protected void onBSCreate() {
super.onBSCreate();
setBSContentView(R.layout.bs_activity);
}}
错误说明:
04-24 18:27:12.659 28763-28763/com.pli.yotaphone2 E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.pli.yotaphone2, PID: 28763
java.lang.RuntimeException: Unable to start service com.pli.yotaphone2.MyBSActivity@42624840 with Intent { cmp=com.pli.yotaphone2/.MyBSActivity }: java.lang.SecurityException: Not allowed to bind to service Intent { act=yotaphone.intent.action.GET_SDK_BINDER }
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2735)
at android.app.ActivityThread.access$2100(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5061)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:603)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.SecurityException: Not allowed to bind to service Intent { act=yotaphone.intent.action.GET_SDK_BINDER }
at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1596)
at android.app.ContextImpl.bindService(ContextImpl.java:1560)
at android.content.ContextWrapper.bindService(ContextWrapper.java:517)
at com.yotadevices.sdk.BSActivity.doBindService(BSActivity.java:137)
at com.yotadevices.sdk.BSActivity.onStartCommand(BSActivity.java:173)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2718)
androidmanifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Service for working with a back screen -->
<service
android:name=".MyBSActivity"
android:exported="true" />
<!-- Adding YotaPhone SDK library -->
<uses-library
android:name="com.yotadevices.yotaphone2.sdk.v2"
android:required="true" />
</application>
答案 0 :(得分:5)
我遇到了完全相同的问题,并且首先认为当前的系统应用程序尚未支持新的SDK。但是,我只是尝试反编译现有的Yota应用程序,并发现我们需要包含权限。教程没有提到的东西。
因此,要修复您的(我们的)问题,您需要在AndroidManifest.xml中包含以下权限:
<uses-permission android:name="com.yotadevices.framework.permission.ACCESS_BACKSCREEN" />
快乐的编码!