public class ReceiverForStartup extends BroadcastReceiver{
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
if(action.equals(Intent.ACTION_BOOT_COMPLETED))
{
Intent i = new Intent(context, "your activity class");
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
2. 在AndroidManifest.xml加入
[receiver android:name=".ReceiverForStartup" android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED"]
[intent-filter]
[action android:name="android.intent.action.BOOT_COMPLETED" /]
[category android:name="android.intent.category.DEFAULT" /]
[/intent-filter]
[/receiver]
沒有留言:
張貼留言