ブロードキャストレシーバーを使用して Intent.ACTION_TIME_TICK を読み取り、毎分サービスからオーディオを再生させています。画面がオフの場合を除いて、すべてが正常に機能し、音が聞こえなくなります。画面をオンのままにするか、画面をオフにしてUSBケーブルを接続すると、再びオンになります。助けてください、ありがとう!
PS。いくつかのテストの後、これは Android 2.3.6 の携帯電話でのみ発生することがわかりました。一方、私の 4.1.2 では問題なく動作します。
@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();
}
}