2011-09-06 209 views

回答

5

此權限是使用

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

在你<應用>元(一定要使用完全合格的[或相對]類名稱爲您的廣播接收器):

<receiver android:name="com.example.MyBroadcastReceiver"> 
    <intent-filter> 
     <action android:name="android.intent.action.BOOT_COMPLETED" /> 
    </intent-filter> 
</receiver> 

In MyBroadcastReceiver.java:

package com.example; 

public class MyBroadcastreceiver extends BroadcastReceiver { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     Intent startServiceIntent = new Intent(context, MyService.class); 
     context.startService(startServiceIntent); 
    } 
} 



更多的幫助:: http://www.androidcompetencycenter.com/2009/06/start-service-at-boot/ http://blog.gregfiumara.com/archives/82 http://androidgps.blogspot.com/2008/09/starting-android-service-at-boot-time.html