0

我有一个应该接收 BOOT 的 BroadcastReceiver。

有没有一种简单的方法来检查 BroadcastReceiver 是否正确接收到 BOOT?

谢谢

4

1 回答 1

2

Assuming BOOT means BOOT_COMPLETED then you could use the following:

public class BootCompleteReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            //Do a Log or, less likely, a Toast or start your application here.
        }
    }
};

You would register this in the manifest like such:

<receiver android:name="com.example.yourAppName.BootReceiver">
   <intent-filter>
     <action android:name="android.intent.action.BOOT_COMPLETED"/>
   </intent-filter>
</receiver>
于 2013-07-19T20:31:47.030 回答