アララム(RTC_WAKEUPタイプ)によってトリガーされるBroadcastReceiverからアクティビティを開始します。そのアクティビティのonCreateで、これらのフラグを追加します
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
);
問題は、画面がオンにならない場合があることです(約10%の場合)。アラームは正しくトリガーされます(ここでは通知の音が受信者のonReceive()でも鳴ります)。その後、電話の電源ボタンを押すと、画面がオンになり、アクティビティが表示され、すぐにオフになります。つまり、電源ボタンはうまく機能します。これはandroid 2.3.7で発生し、これがonReceive()メソッドです。
@Override
public void onReceive(Context context, Intent intent) {
m_Context = context;
Bundle extras = intent.getExtras();
final int id = extras.getInt("timer_id");
Intent activityIntent = new Intent(m_Context, MyActivity.class);
activityIntent.putExtra("timer_id", id);
activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
m_Context.startActivity(activityIntent);
// and now load the alarm sound and play it for the desired time
showFinishedNotification();
}
PowerManagerの使用は許可が必要であり、フラグが推奨される方法であるため、使用を避けたいと思います。
何が問題になる可能性がありますか?logcatは問題を示していません...