我無法啓動服務,當我想在啓動時爲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