我正在使用广播接收器在设备关闭并再次打开时执行某些操作,但它们不起作用。这些是清单文件中的接收器:
<receiver android:name=".ShutdownReceiver" >
<intent-filter>
<action android:name="android.intent.action.ACTION_SHUTDOWN" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.QUICKBOOT_POWEROFF" />
</intent-filter>
</receiver>
<receiver android:name=".RestartReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
这些是相应的类:
public class ShutdownReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.d("In","Switched Off");
}
}
public class RestartReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
SecureMessagesActivity.ToDoOnMobileSwitchOn();
Log.d("In","Switched On");
}
}
请帮帮我。谢谢。
答案 0 :(得分:2)
请务必在清单中请求RECEIVE_BOOT_COMPLETED
权限:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>