2012-09-24 2 views
0

내 작업에서 미리 알림 확인 프로세스를 수행했습니다. 미리 알림 시간이 현재 시간과 같으면 팝업 상자가 나타납니다. 이 작업에서는 팝업 상자가 올바르게 나타납니다.안드로이드에서 프론트 스크린에 경고가 팝업되어야합니다.

하지만이 작업을 큰 프로세스로 병합하면 알림 작업이 주 프로그램의 하위 프로그램이됩니다. 팝업이 다른 화면에 나타나지 않습니다. 사용자가이 프로그램의 화면 중 하나를 사용하는 동안 시간 만난 현재 시간 경우, 경고가이 경고 메시지에서 ..., 사용자에

if (LDbTime <= LSysTime) { 
            rem_id = c.getString(c.getColumnIndex("reminder_id")); 
            remName = c.getString(c.getColumnIndex("rname")); 
            mediaPlayer.start(); 
            handler.post(new Runnable(){ 
            public void run() { 
             alert.setTitle("Alert :"+remName); 
             alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
              public void onClick(DialogInterface dialog, int whichButton) { 
               mediaPlayer.pause(); 
              } 
             }); 
             alert.show(); 
             db1.execSQL("UPDATE RemainAlarmS SET expired ='TRUE' WHERE reminder_id = " + rem_id); 
              } 
             }); 
            Thread.sleep(5000); 
           } 

를 표시해야한다은시 전면 화면에 대한 지참해야 알리미 깨우기.

솔루션을 찾기 위해 제발 도와주세요 .. 미리

감사합니다.

답변

2

당신은 의도 보류에 대한 다음과 같은 코드를 사용할 수 ..

Intent i = new Intent("android.intent.action.DA"); 
PendingIntent operation = PendingIntent.getActivity(getBaseContext(), 0, i, Intent.FLAG_ACTIVITY_NEW_TASK); 
AlarmManager alarmManager = (AlarmManager) getBaseContext().getSystemService(ALARM_SERVICE); 
GregorianCalendar calendar = new GregorianCalendar(y,m,d, hr, mi); 
long alarm_time = calendar.getTimeInMillis(); 
alarmManager.set(AlarmManager.RTC_WAKEUP , alarm_time , operation); 

그리고 "안드로이드. int.action.DA "는 DisplayNotification.java 클래스의 Activity를 나타냅니다.

public class DisplayNotification extends Activity { 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    int notifID = getIntent().getExtras().getInt("NotifID"); 
    Intent i = new Intent("android.intent.action.AD"); 
    i.putExtra("NotifID", notifID); 
    PendingIntent detailsIntent =PendingIntent.getActivity(this, 0, i, 0); 
    NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
    Notification notif = new Notification(R.drawable.ic_launcher,"Time's up!",System.currentTimeMillis()); 
    CharSequence from = "AlarmManager - Time's up!"; 
    CharSequence message = "This is your alert, courtesy of the AlarmManager";   
    notif.setLatestEventInfo(this, from, message, detailsIntent); 
    notif.vibrate = new long[] { 100, 250, 100, 500};   
    nm.notify(notifID, notif); 
    finish(); 
} 
} 

그리고 "android.intent.action.AD"나는이 도움이 될 것입니다 당신! ..

-1

대신 상태 표시 줄 알림을 사용할 수 있습니다.

+0

는 현재 실행 또는 전면 화면에 필요 희망 AlarmDetails.java 클래스

public class AlarmDetails extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.alarmdetails); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); //---cancel the notification--- nm.cancel(getIntent().getExtras().getInt("NotifID")); } } 

을 의미한다. – gowri

2

귀하의 활동이 사용자의 전화 활동에 집중되지 않은 경우 대화 상자를 표시하는 방법을 묻는 경우 알림을 대신 사용해보십시오. 다른 응용 프로그램을 통해 대화 상자를 표시하면 사용자가 다른 작업을 수행 할 때 인터럽트됩니다. 안드로이드 UI 가이드 라인에서 :

Use the notification system — don't use dialog boxes in place of notifications 

If your background service needs to notify a user, use the standard notification system — 
don't use a dialog or toast to notify them. A dialog or toast would immediately 
take focus and interrupt the user, taking focus away from what they were doing: 
the user could be in the middle of typing text the moment the dialog appears 
and could accidentally act on the dialog. 
Users are used to dealing with notifications and 
can pull down the notification shade at their convenience to respond to your message. 

알림을 만들 수있는 가이드는 여기에 있습니다 : http://developer.android.com/guide/topics/ui/notifiers/notifications.html