【发布时间】:2016-07-14 11:24:46
【问题描述】:
我的目标是启动一项服务,该服务通过 .jar 文件作为 Android 插件添加到 Unity3D 中。在this 线程中,我发现了如何启动它,我最终可以使用本机代码。但是我在日志中遇到了如下问题:
07-14 15:02:23.965: W/ActivityManager(444): Unable to start service Intent { cmp=net.calipssoone.bnh/com.activitychecker.adservice.CheckService } U=0: not found
我用谷歌搜索发现问题出在清单中,但无法弄清楚我做错了什么。下面是在清单中声明服务的方式:
<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true">
<service android:name="com.activitychecker.adservice.CheckService"/>
<receiver android:name="com.activitychecker.adservice.StartReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
<action android:name="CheckService" />
</intent-filter>
</receiver>
它在Java中的包名其实是一样的:com.activitychecker.adservice
StartReceiver 类:
public class StartReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {}
}
CheckService 类:
public class CheckService extends Service {
public void onCreate(){}
public long getCurrentTime(){}
public void loadInfo(){}
public int onStartCommand(Intent intent, int flags, int startId){}
public void onDestroy() {}
public IBinder onBind(Intent intent) {}
public class MyThread extends Thread {
public void run() {}
public void cancel() {}
public boolean check(String bundle){}
}
private class ScreenBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {}
}
}
统一更新: 我已将清单更改为:
<service android:name="com.activitychecker.adservice.CheckService"/>
收件人:
<service android:name="com.activitychecker.adservice.CheckService"></service>
并且日志错误变为:
07-14 17:46:13.455: W/ActivityManager(444): Unable to start service Intent { act=com.activitychecker.adservice.CheckService } U=0: not found
【问题讨论】:
-
如果您发布 CheckService 和 StartReceiver 类会很好。我不想看到它们里面的代码。只是它的蓝图和其中的功能。
-
你试过this吗?
-
我已经更新了问题代码,@Programmer
-
@UmairM 如果该答案的目的是通过字符串调用意图,我刚刚尝试过,但没有任何成功。我的清单中没有任何“远程”属性。服务属性在应用标签内,并且有完整的包路径,因为它在另一个包中。
-
我今天做了实验,我想我找到了你的问题。不太确定,但这个问题解决了吗?
标签: c# android unity3d plugins service