我收到的错误是
2022-01-28 11:10:42.186 1651-3045/? W/ActivityManager: Unable to start service Intent { act=nveeaidle pkg=com.rchan.nveeapplication } U=0: not found
我已经在我的两个应用程序(客户端和服务器(中确保了以下代码。在我的服务器清单中:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rchan.nveeapplication">
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NveeApplication">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="com.rchan.nvee_sdk.detectedactivity.DetectedActivityService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="nveeaidle" />
</intent-filter>
</service>
<receiver android:name="com.rchan.nvee_sdk.detectedactivity.DetectedActivityReceiver"/>
<!-- <receiver-->
<!-- android:name="com.rchan.nvee_sdk.detectedactivity.DetectedActivityReceiver"-->
<!-- android:exported="false"-->
<!-- android:process=":remote"-->
<!-- android:permission="com.google.android.gms.permission.ACTIVITY_RECOGNITION">-->
<!-- <intent-filter>-->
<!-- <action android:name="action.TRANSITIONS_DATA" />-->
<!-- </intent-filter>-->
<!-- </receiver>-->
</application>
</manifest>
在我的客户中,我的片段中有这样的内容:
private fun connectToRemoteService() {
val intent = Intent("nveeaidle")
val pack = "com.rchan.nveeapplication"
pack?.let {
intent.setPackage(pack)
activity?.applicationContext?.bindService(
intent, this, Context.BIND_AUTO_CREATE
)
}
}
我不确定是什么导致了这个警告,在stackoverflow和谷歌上搜索后,我尝试了不同的解决方案。
我该如何测试:
- 启动我的服务器应用程序
- 启动我的客户端应用程序
- 我看到了警告
感谢您花时间阅读我的问题。
经过最近的更改,您可以使用<查询>lt;包android:name="您的包裹名称"/>lt/查询>
https://developer.android.com/training/package-visibility/declaring
我做了更多的搜索,终于找到了答案。。。所有学分都转到SO这里的答案:
https://stackoverflow.com/a/55712326/3718584
TLDR:
由于API 21 ,不得不将意图从隐含改为明确
intent.setClassName("com.rchan.nveeapplication","com.rchan.nvee_sdk.detectedactivity.DetectedActivityService")