Search code examples
javaandroidandroid-intentandroid-servicesecurityexception

Not allowed to bind to service Intent when starting a service


I am now developing an android App. When I want to start a service, I face the problem: Not allowed to bind to service Intent. The service is Yotaphone back screen service.

I search for the problem, there are very little information, most of them are not the same kind of problem. I have no idea which part goes wrong.

I fellow the instructions: http://mwiki.yotaphone.com/wiki/Building_First_App.

The onStart() function in MainActivity:

@Override
protected void onStart() {
    super.onStart();
    Intent bsIntent = new Intent(this, MyBSActivity.class);
    this.startService(bsIntent);

}

The Yotaphone back screen service:

public class MyBSActivity extends BSActivity {
@Override
protected void onBSCreate() {
    super.onBSCreate();
    setBSContentView(R.layout.bs_activity);
}}

The error description:

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)

            

The 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>


Solution

  • I ran into the exact same problem, and first thought it was that the current system apps didn't yet support the new SDK. However, I just tried to decompile an existing Yota app, and found that we need to include a permission. Something that the tutorial fails to mention.

    So to fix your (our) problem, you need to include the following permission in your AndroidManifest.xml:

    <uses-permission android:name="com.yotadevices.framework.permission.ACCESS_BACKSCREEN" />
    

    Happy coding!