我的目標是啓動一個服務,該服務通過.jar文件作爲Unity3D中的android插件添加。在this線程中,我發現如何啓動它,我可以finnaly獲得本地代碼。但我已經遇到了以下問題日誌中:Unity3D Android插件:無法啓動服務
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
我用Google搜索,並發現問題是在清單中,但無法弄清楚什麼我做錯了。這裏的服務是如何在清單中聲明:
<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) {}
}
}
UPD:
<service android:name="com.activitychecker.adservice.CheckService"/>
要: 我已經從改變了我的manifset
<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類這將是一件好事。我不想看到裏面的代碼。只是它的藍圖和它的功能。 – Programmer
你有沒有試過[this](http://stackoverflow.com/a/3439838/4366237)? –
我已經更新了問題代碼,@Programmer –