홈 화면에 경고 대화 상자를 표시하는 알람을 실행하려고합니다. 즉 애플리케이션이 닫히고 이벤트 시간에 도달하면 알림 대화 상자에 이벤트의 제목이 표시되고 무한정 울립니다. 경고 대화 상자에서 버튼을 클릭하면, 알람은 다음과 같이 내 코드가 꺼지면 :홈 화면에 알림 대화 상자를 표시하는 방법은 무엇입니까?
void doReminderWork(Intent intent) {
ToDoApplicationActivity ap = new ToDoApplicationActivity();
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(this, ToDoApplicationActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_ONE_SHOT);
Notification note = new Notification(R.drawable.alarm, "...Calendar Alarm...", System.currentTimeMillis());
note.setLatestEventInfo(this,"Event : ", ap.title1, pi);
note.defaults |= Notification.DEFAULT_SOUND;
note.flags |= Notification.FLAG_AUTO_CANCEL;
int id = 123456789;
manager.notify(id, note);
Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
mMediaPlayer = new MediaPlayer();
try {
mMediaPlayer.setDataSource(this, alert);
} catch (IllegalArgumentException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SecurityException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalStateException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
final AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
if (audioManager.getStreamVolume(AudioManager.STREAM_ALARM) != 0)
{
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mMediaPlayer.setLooping(false);
try
{
mMediaPlayer.prepare();
}
catch (IllegalStateException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
mMediaPlayer.start();
}
을 이후 나는 미디어 플레이어를 중지 경고 대화 코드를 제공하는 경우, 내가 그것을 알람 재생을 중지하지 못할 것을 알고있다. 여기에서 응용 프로그램이 닫힌 경우에도 알림 대화 상자를 표시해야합니다. 나는 지난 2 일 동안 이것을 시도하고있다. 당신이 알람 통지를받을 때 당신이 가지고있는 활동에 경고 대화 상자를 표시 할 수 있습니다
대화처럼 테마 활동을 할 수 있습니다. 자세한 내용은 여기를 참조하십시오. http://stackoverflow.com/questions/3167843/how-does-froyo-display-a-dialog-atop-the-home-screen – Tomik
예외 다음 : android.view.WindowManager $ BadTokenException : 창을 추가 할 수 없습니다 - 응용 프로그램에 대해 토큰 null이 없습니다. –