屏幕关闭后Android广播接收器未启动
我正在使用广播接收器读取Intent.ACTION\u TIME\u滴答声,让它每分钟播放一次服务中的音频。一切正常,但当屏幕关闭时,它不再发出声音。如果我一直打开屏幕或在屏幕关闭的情况下插入usb电缆,它会重新打开。请帮忙,谢谢 另外,经过几次测试,我发现这只发生在我的安卓2.3.6手机上,而在我的4.1.2手机上,它运行没有问题屏幕关闭后Android广播接收器未启动,android,service,broadcastreceiver,Android,Service,Broadcastreceiver,我正在使用广播接收器读取Intent.ACTION\u TIME\u滴答声,让它每分钟播放一次服务中的音频。一切正常,但当屏幕关闭时,它不再发出声音。如果我一直打开屏幕或在屏幕关闭的情况下插入usb电缆,它会重新打开。请帮忙,谢谢 另外,经过几次测试,我发现这只发生在我的安卓2.3.6手机上,而在我的4.1.2手机上,它运行没有问题 @Override public IBinder onBind(Intent arg0) { return null; } @Override p
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
registerReceiver(new TickReceiver(), new IntentFilter(
Intent.ACTION_TIME_TICK));
mp = MediaPlayer.create(this, R.raw.cuckoo);
}
@Override
public void onStart(Intent intent, int startId) {
notifyMe();
}
@Override
public void onDestroy() {
clearNotification();
if (mp != null){
mp.release();
mp = null;
}
}
public void notifyMe() {
note = new Notification(R.drawable.front, "Message Inbound!",
System.currentTimeMillis());
PendingIntent i = PendingIntent.getActivity(this, 0, new Intent(this,
LeftAndRightActivity.class), Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_NEW_TASK);
note.setLatestEventInfo(this, "Title...", "Subtitle", i);
note.flags = note.flags | Notification.FLAG_ONGOING_EVENT;
mgr.notify(NOTIFY_ME_ID, note);
}
public void clearNotification() {
mgr.cancel(NOTIFY_ME_ID);
}
public void playBeep() {
mp.start();
}
public class TickReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
playBeep();
}
}
尝试在oncreate中执行此操作:
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
BroadcastReceiver mReceiver = new ScreenReceiver();
registerReceiver(mReceiver, filter);
您在清单中保存的最小sdk是什么?