试图在android上启动一个服务当设备在Android上启动时,我一直试图启动一项服务,但我无法让它开始工作。我看过很多在线链接,但是没有一个代码有效。我是不是忘了什么?AndroidManifest.xml<receiver
android:name=".StartServiceAtBootReceiver"
android:enabled="true"
android:exported="false"
android:label="StartServiceAtBootReceiver" >
<intent-filter>
<action android:name="android.intent.action._BOOT_COMPLETED" />
</intent-filter></receiver><service
android:name="com.test.RunService"
android:enabled="true" />广播收发器public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceLauncher = new Intent(context, RunService.class);
context.startService(serviceLauncher);
Log.v("TEST", "Service loaded at start");
}}
添加回答
举报
0/150
提交
取消