本文介绍了应用程序将无法绑定服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想结合这包括在用如下的库项目服务:
意向书I =新意图();
i.setClassName(de.ring0,de.ring0.ToolkitService);
bindService(我,这一点,Context.BIND_AUTO_CREATE);
绑定过程失败,下面的调试输出。按照Android开发者文档中的两个清单文件的选项应该是正确的。
的AndroidManifest.xml图书馆项目
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=de.ring0>
<采用-SDK安卓的minSdkVersion =8/>
<应用机器人:可调试=真正的>
<服务机器人:名字=de.ring0.ToolkitService机器人:出口=真正的机器人:启用=真/>
< /用途>
< /清单>
AndroidManifest.xml中主项目
<?XML版本=1.0编码=UTF-8&GT?;
<清单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=de.ring0.example.tactilecompass
安卓版code =1
机器人:=的versionName1.0>
<采用-SDK安卓的minSdkVersion =8/> <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAGE>< /使用许可权>
<使用许可权的android:NAME =android.permission.ACCESS_COARSE_LOCATION/>
<使用许可权的android:NAME =android.permission.ACCESS_FINE_LOCATION>< /使用许可权>
<使用许可权的android:NAME =android.permission.VIBRATE>< /使用许可权> <应用机器人:图标=@绘制/图标机器人:标签=@字符串/ APP_NAME机器人:可调试=真正的>
<活动机器人:名字=。TactileCompassActivity
机器人:标签=@字符串/ APP_NAME>
&所述;意图滤光器>
<作用机器人:名字=android.intent.action.MAIN/>
<类机器人:名字=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
<服务机器人:名字=de.ring0.ToolkitService/>
< /用途>
< /清单>
调试日志从模拟器
W / ActivityManager(59):权限被拒绝:checkComponentPermission()reqUid = 10036
W / ActivityManager(59):拒绝权限:访问服务ComponentInfo从PID = 2994 {de.ring0 / de.ring0.ToolkitService},UID = 10037需要空
W / dalvikvm(2994):主题ID = 1:螺纹未捕获的异常退出(组= 0x4001d800)
E / AndroidRuntime(2994):致命异常:主要
E / AndroidRuntime(2994):了java.lang.RuntimeException:无法启动活动ComponentInfo{de.ring0.example.tactilecompass/de.ring0.example.tactilecompass.TactileCompassActivity}: java.lang.SecurityException异常:不允许绑定到服务意向{CMP = de.ring0 / .ToolkitService}
E / AndroidRuntime(2994):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E / AndroidRuntime(2994):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E / AndroidRuntime(2994):在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)
E / AndroidRuntime(2994):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)
E / AndroidRuntime(2994):在android.os.Handler.dispatchMessage(Handler.java:99)
E / AndroidRuntime(2994):在android.os.Looper.loop(Looper.java:123)
E / AndroidRuntime(2994):在android.app.ActivityThread.main(ActivityThread.java:4627)
E / AndroidRuntime(2994):在java.lang.reflect.Method.invokeNative(本机方法)
E / AndroidRuntime(2994):在java.lang.reflect.Method.invoke(Method.java:521)
E / AndroidRuntime(2994):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
E / AndroidRuntime(2994):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E / AndroidRuntime(2994):在dalvik.system.NativeStart.main(本机方法)
E / AndroidRuntime(2994):java.lang.SecurityException异常:产生的原因不允许绑定到服务意向{CMP = de.ring0 / .ToolkitService}
E / AndroidRuntime(2994):在android.app.ContextImpl.bindService(ContextImpl.java:874)
E / AndroidRuntime(2994):在android.content.ContextWrapper.bindService(ContextWrapper.java:347)
E / AndroidRuntime(2994):在de.ring0.example.tactilecompass.TactileCompassActivity.onCreate(TactileCompassActivity.java:28)
E / AndroidRuntime(2994):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E / AndroidRuntime(2994):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E / AndroidRuntime(2994):11 ...更多
W / ActivityManager(59):过程de.ring0.example.tactilecompass已经崩溃了太多次:杀!
W / ActivityManager(59):强制完成活动de.ring0.example.tactilecompass / .TactileCompassActivity
I /过程(59):发送信号。 PID:2994 SIG:9
解决方案
使用:
新意图(这一点,de.ring0.ToolkitService.class);
I am trying to bind a service which is included in a Library project with the following lines:
Intent i = new Intent();
i.setClassName("de.ring0", "de.ring0.ToolkitService");
bindService(i, this, Context.BIND_AUTO_CREATE);
The binding process fails with the debug output below. According to the Android developer documentation the options in the two manifest files should be correct.
AndroidManifest.xml Library Project
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.ring0">
<uses-sdk android:minSdkVersion="8" />
<application android:debuggable="true">
<service android:name="de.ring0.ToolkitService" android:exported="true" android:enabled="true"/>
</application>
</manifest>
AndroidManifest.xml Main Project
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.ring0.example.tactilecompass"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name=".TactileCompassActivity"
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 android:name="de.ring0.ToolkitService" />
</application>
</manifest>
Debug Log from emulator
W/ActivityManager( 59): Permission denied: checkComponentPermission() reqUid=10036
W/ActivityManager( 59): Permission Denial: Accessing service ComponentInfo{de.ring0/de.ring0.ToolkitService} from pid=2994, uid=10037 requires null
W/dalvikvm( 2994): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime( 2994): FATAL EXCEPTION: main
E/AndroidRuntime( 2994): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.ring0.example.tactilecompass/de.ring0.example.tactilecompass.TactileCompassActivity}: java.lang.SecurityException: Not allowed to bind to service Intent { cmp=de.ring0/.ToolkitService }
E/AndroidRuntime( 2994): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime( 2994): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime( 2994): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime( 2994): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime( 2994): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2994): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 2994): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime( 2994): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2994): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 2994): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime( 2994): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime( 2994): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 2994): Caused by: java.lang.SecurityException: Not allowed to bind to service Intent { cmp=de.ring0/.ToolkitService }
E/AndroidRuntime( 2994): at android.app.ContextImpl.bindService(ContextImpl.java:874)
E/AndroidRuntime( 2994): at android.content.ContextWrapper.bindService(ContextWrapper.java:347)
E/AndroidRuntime( 2994): at de.ring0.example.tactilecompass.TactileCompassActivity.onCreate(TactileCompassActivity.java:28)
E/AndroidRuntime( 2994): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 2994): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime( 2994): ... 11 more
W/ActivityManager( 59): Process de.ring0.example.tactilecompass has crashed too many times: killing!
W/ActivityManager( 59): Force finishing activity de.ring0.example.tactilecompass/.TactileCompassActivity
I/Process ( 59): Sending signal. PID: 2994 SIG: 9
解决方案
Use:
new Intent(this, de.ring0.ToolkitService.class);
这篇关于应用程序将无法绑定服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!