广播接收器在机器人装置的情况下,关断和接通不工作(broadcastreceiver in case

2019-10-17 08:12发布

我使用的广播接收机,用于当设备被关闭并重新开启一些行动,但他们不是working.These在清单文件的接收器:

  <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");
    }
}

请帮助me.Thanks提前。

Answer 1:

务必请RECEIVE_BOOT_COMPLETED允许在你的清单:

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


文章来源: broadcastreceiver in case of android device switched off and on not working