为什么绑定到另一个应用程序中的服务失败?显式意图使用字符串参数
Why binding to a Service in another application fails? Explicit intent uses string parameters
尝试使用 Messenger 为客户端执行 ipc 以绑定到服务,如此处所示。
http://developer.android.com/guide/components/bound-services.html#Lifecycle
我的服务是com.x.laser中的LaserApp,客户端是com.x中的LaserClientActivity。laserclient .
该服务运行宁作为系统服务,我已经构建了客户端和服务,使用相同的证书对两者进行签名。
我收到错误:
W/ContextImpl( 2468): Calling a method in the system process without a
qualified user: android.app.ContextImpl.bindService:1762
android.content.ContextWrapper.bindService:517
com.x.laserclient.LaserClientActivity.onStart:123
android.app.Instrumentation.callActivityOnStart:1171
和
android.app.Activity.performStart:5276 W/ActivityManager( 2053):
Unable to start service Intent { cmp=com.x.laser/LaserApp } U=0: not
found
请注意,显式意图使用字符串参数。
在客户端,我是这样绑定的:
@Override
protected void onStart() {
super.onStart();
// Bind to the service
Intent i = new Intent();
i.setClassName("com.x.laser", "LaserApp");
// i.setClassName(this, LaserApp.class);
Log.d(TAG, "bind to LaserApp ");
bindService(i, mConnection,
Context.BIND_AUTO_CREATE);
}
承载该服务的应用程序具有清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.x.laser"
android:sharedUserId="android.uid.system" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<application
android:name=".StartlaserApp"
android:allowBackup="true"
android:icon="@drawable/laser_icon"
android:label="@string/app_name"
android:persistent="true"
android:theme="@style/AppTheme" >
<service android:name=".LaserApp"
android:exported="true"/>
<activity
android:name=".MainLauncher"
android:label="@string/main_launcher" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
客户端清单是:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.x.laserclient"
android:sharedUserId="android.uid.system"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".LaserClientActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
update:我必须使用完全限定的组件名称,使客户端 运行 成为相同的用户 ID - 系统,并按顺序使用相同的证书签名让它工作。但对我来说,这削弱了任何客户端都可以绑定到服务的概念。我不明白,但我的直接目的达到了
替换为:
i.setClassName("com.x.laser", "LaserApp");
有了这个:
i.setClassName("com.x.laser", "com.x.laser.LaserApp");
Component
的 "class name" 部分必须完全限定。
尝试使用 Messenger 为客户端执行 ipc 以绑定到服务,如此处所示。 http://developer.android.com/guide/components/bound-services.html#Lifecycle
我的服务是com.x.laser中的LaserApp,客户端是com.x中的LaserClientActivity。laserclient .
该服务运行宁作为系统服务,我已经构建了客户端和服务,使用相同的证书对两者进行签名。
我收到错误:
W/ContextImpl( 2468): Calling a method in the system process without a qualified user: android.app.ContextImpl.bindService:1762 android.content.ContextWrapper.bindService:517 com.x.laserclient.LaserClientActivity.onStart:123 android.app.Instrumentation.callActivityOnStart:1171
和
android.app.Activity.performStart:5276 W/ActivityManager( 2053): Unable to start service Intent { cmp=com.x.laser/LaserApp } U=0: not found
请注意,显式意图使用字符串参数。
在客户端,我是这样绑定的:
@Override
protected void onStart() {
super.onStart();
// Bind to the service
Intent i = new Intent();
i.setClassName("com.x.laser", "LaserApp");
// i.setClassName(this, LaserApp.class);
Log.d(TAG, "bind to LaserApp ");
bindService(i, mConnection,
Context.BIND_AUTO_CREATE);
}
承载该服务的应用程序具有清单:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.x.laser"
android:sharedUserId="android.uid.system" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<application
android:name=".StartlaserApp"
android:allowBackup="true"
android:icon="@drawable/laser_icon"
android:label="@string/app_name"
android:persistent="true"
android:theme="@style/AppTheme" >
<service android:name=".LaserApp"
android:exported="true"/>
<activity
android:name=".MainLauncher"
android:label="@string/main_launcher" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
客户端清单是:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.x.laserclient"
android:sharedUserId="android.uid.system"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".LaserClientActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
update:我必须使用完全限定的组件名称,使客户端 运行 成为相同的用户 ID - 系统,并按顺序使用相同的证书签名让它工作。但对我来说,这削弱了任何客户端都可以绑定到服务的概念。我不明白,但我的直接目的达到了
替换为:
i.setClassName("com.x.laser", "LaserApp");
有了这个:
i.setClassName("com.x.laser", "com.x.laser.LaserApp");
Component
的 "class name" 部分必须完全限定。