我不知道为什么,但在某些设备中,我的服务不允许绑定。
java.lang.RuntimeException: Unable to create application mypackage.MyApplication: java.lang.SecurityException: Unable to find app for caller android.app.ApplicationThreadProxy@41680e78 (pid=16805) when binding service Intent { cmp=mypackage/.MyService }
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4394)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.SecurityException: Unable to find app for caller android.app.ApplicationThreadProxy@41680e78 (pid=16805) when binding service Intent { cmp=mypackage/.MyService }
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.app.ActivityManagerProxy.bindService(ActivityManagerNative.java:2720)
at android.app.ContextImpl.bindService(ContextImpl.java:1431)
at android.app.ContextImpl.bindService(ContextImpl.java:1407)
at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
at mypackage.MyApplication.openService(MyApplication.java:151)
at mypackage.MyApplication.onCreate(MyApplication.java:110)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1000)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4391)
... 10 more
java.lang.SecurityException: Unable to find app for caller android.app.ApplicationThreadProxy@41680e78 (pid=16805) when binding service Intent { cmp=mypackage/.MyService }
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at android.app.ActivityManagerProxy.bindService(ActivityManagerNative.java:2720)
at android.app.ContextImpl.bindService(ContextImpl.java:1431)
at android.app.ContextImpl.bindService(ContextImpl.java:1407)
at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
at mypackage.MyApplication.openService(MyApplication.java:151)
at mypackage.MyApplication.onCreate(MyApplication.java:110)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1000)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4391)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
来自 MyApplication 的代码:
@Override
public void onCreate() {
super.onCreate();
openService();
}
public void openService() {
Intent service = new Intent(this, MyService.class);
mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mService = IMyService.Stub.asInterface(service);
if (mListener != null) {
mListener.onServiceStarted(mService);
}
}
@Override
public void onServiceDisconnected(ComponentName cn) {
mService = null;
}
};
bindService(service, mConnection, Context.BIND_AUTO_CREATE); // 151 line
}
显现:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mypackage"
android:versionCode="25"
android:versionName="2.3.2" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:name=".MyApplication"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/CustomTheme"
android:allowBackup="true" >
<!-- android:configChanges="orientation" -->
<activity
android:name=".ui.activities.NewSearchActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- other activities -->
<service
android:name="mypackage.MyService"
android:enabled="true" />
</application>
</manifest>
请帮我!谢谢!