我无法启动服务,当我想在启动时为Android 4.0的Android服务启动服务。 我的代码如下:在启动时为Android 4.0启动服务
> public class StartUpReceiver extends BroadcastReceiver{ @Override
> public void onReceive(Context context, Intent intent) { String
> action = intent.getAction(); if
> (action.equalsIgnoreCase("android.intent.action.BOOT_COMPLETED")) {
> Intent myIntent = new Intent(context, StartAUT_Service.class);
> Log.i("Broadcast", "startService on boot time:." + myIntent);
> context.startService(myIntent); }
> } }
> <uses-permission
> android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
> <application android:icon="@drawable/icon" android:label="@string/app_name">
> <receiver android:name="com.Android.Exercise.StartUpReceiver" android:exported="false">
> <intent-filter>
> <action android:name="android.intent.action.BOOT_COMPLETED"/>
> <action android:name="StartInstrument" />
> <action android:name="PrintControlName" />
> </intent-filter>
> </receiver>
> <service android:enabled="true" android:name="StartAUT_Service">
> <intent-filter>
> <action android:name="com.Android.Exercise.StartAUT_Service" />
> </intent-filter>
> </service>
> </application>
而且在logcat中显示关闭VM当我在上面跑项目,所以我的广播没有收到行动。 Plz帮助我。 非常感谢。
感谢您的回复,我试过了,但它仍然有错误, 第一我不能把“super.onReceive”放在这段代码中(语法错误)。 第二次当我复制你的代码来替换我的代码时,它仍然不能运行。 – user1266236 2012-03-14 02:40:20
@ user1266236:在设备启动完成时,我在我的项目中使用了上述代码来启动服务。它对我的项目 – Prasad 2012-03-14 05:22:24