android电话广播有时候失效,Android ACTION_SHUTDOWN广播无效
代码 –public class ShutdownReceiver extends BroadcastReceiver {private static final String TAG = "ShutdownReceiver";@Overridepublic void onReceive(final Context context, final Intent intent) {Logger.i(T
代码 –
public class ShutdownReceiver extends BroadcastReceiver {
private static final String TAG = "ShutdownReceiver";
@Override
public void onReceive(final Context context, final Intent intent) {
Logger.i(TAG, "Shutting Down..........................");
if("android.intent.action.ACTION_SHUTDOWN".equals(intent.getAction())) {
//Power Off
}
}
}
服务 –
private BroadcastReceiver mReceiver = null;
@Override
public void onCreate() {
super.onCreate();
// INITIALIZE RECEIVER
//It is used to register broadcast for ShutDown or Power Off
IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
mReceiver = new ShutdownReceiver();
registerReceiver(mReceiver, filter);
}
@Override
public void onDestroy() {
unregisterReceiver(mReceiver);
}
权限 –
更多推荐
所有评论(0)