Android 为什么绑定到另一个应用程序中的服务失败?显式意图使用字符串参数
尝试使用Messenger为客户端执行ipc以绑定到服务,如图所示。 我的服务是com.x中的LaserApp。laser,客户是com.x中的laserclient 该服务作为系统运行服务,我构建了客户端和服务,并使用相同的证书对两者进行签名 我得到一个错误: W/ContextImpl(2468):在没有 合格用户: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): 无法启动服务意图{cmp=com.x.laser/LaserApp}U=0:未启动 发现 请注意,显式意图使用字符串参数 在客户机中,我约束如下:Android 为什么绑定到另一个应用程序中的服务失败?显式意图使用字符串参数,android,android-intent,Android,Android Intent,尝试使用Messenger为客户端执行ipc以绑定到服务,如图所示。 我的服务是com.x中的LaserApp。laser,客户是com.x中的laserclient 该服务作为系统运行服务,我构建了客户端和服务,并使用相同的证书对两者进行签名 我得到一个错误: W/ContextImpl(2468):在没有 合格用户:android.app.ContextImpl.bindService:1762 android.content.ContextWrapper.bindService:517
@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>
更新:我必须使用完全限定的组件名,使客户端以相同的用户id-系统运行,并使用相同的证书进行签名,以使其正常工作。但对我来说,这削弱了任何客户端都可以绑定到服务的概念。我不明白,但我的直接目的已经实现了替换这个:
i.setClassName("com.x.laser", "LaserApp");
为此:
i.setClassName("com.x.laser", "com.x.laser.LaserApp");
组件的“类名”部分必须完全合格。替换此部分:
i.setClassName("com.x.laser", "LaserApp");
为此:
i.setClassName("com.x.laser", "com.x.laser.LaserApp");
组件的“类名”部分必须完全合格。替换此部分:
i.setClassName("com.x.laser", "LaserApp");
为此:
i.setClassName("com.x.laser", "com.x.laser.LaserApp");
组件的“类名”部分必须完全合格。替换此部分:
i.setClassName("com.x.laser", "LaserApp");
为此:
i.setClassName("com.x.laser", "com.x.laser.LaserApp");
组件的“类名”部分必须是完全限定的。我试过了-根据您在别处的SO答案,它不起作用。我会再试一次,以防我没有考虑到的某些变化。这可能是您将其设置为系统服务的方式中的一个问题。关于在没有合格用户的情况下调用方法的错误消息让我感到紧张。您是否考虑过使用隐式Intent
而不是显式(只是为了看看您是否可以让它工作)?我必须让客户端以相同的用户id-系统运行,并使用相同的证书签名才能使其工作。但对我来说,这削弱了任何客户端都可以绑定到服务的概念。我不明白,但我的直接目的已经实现了。我确实尝试过了——根据你在别处的SO回答,它不起作用。我会再试一次,以防我没有考虑到的某些变化。这可能是您将其设置为系统服务的方式中的一个问题。关于在没有合格用户的情况下调用方法的错误消息让我感到紧张。您是否考虑过使用隐式Intent
而不是显式(只是为了看看您是否可以让它工作)?我必须让客户端以相同的用户id-系统运行,并使用相同的证书签名才能使其工作。但对我来说,这削弱了任何客户端都可以绑定到服务的概念。我不明白,但我的直接目的已经实现了。我确实尝试过了——根据你在别处的SO回答,它不起作用。我会再试一次,以防我没有考虑到的某些变化。这可能是您将其设置为系统服务的方式中的一个问题。关于在没有合格用户的情况下调用方法的错误消息让我感到紧张。您是否考虑过使用隐式Intent
而不是显式(只是为了看看您是否可以让它工作)?我必须让客户端以相同的用户id-系统运行,并使用相同的证书签名才能使其工作。但对我来说,这削弱了任何客户端都可以绑定到服务的概念。我不明白,但我的直接目的已经实现了。我确实尝试过了——根据你在别处的SO回答,它不起作用。我会再试一次,以防我没有考虑到的某些变化。这可能是您将其设置为系统服务的方式中的一个问题。关于在没有合格用户的情况下调用方法的错误消息让我感到紧张。您是否考虑过使用隐式Intent
而不是显式(只是为了看看您是否可以让它工作)?我必须让客户端以相同的用户id-系统运行,并使用相同的证书签名才能使其工作。但对我来说,这削弱了任何客户端都可以绑定到服务的概念。我不明白,但我的直接目的实现了。