2012-04-14 3 views
2

나는 구성 할 앱을 개발하려고합니다. 그래서 특정 시간에 작업을 설정 한 후, 알림을 생성 했으므로 상태 표시 줄에이 알림이 표시되고 사용자가이를 터치하면 현재 활동이 표시됩니다.
내 문제는 : 알림이 나타나면 활동도 시작됩니다.
어쨌든 이것을 방지 할 수 있습니까? 나는 활동이 알림이 나타날 때 자동으로 시작되지 않으며 사용자가 활동을 깨우기 위해 알림을 클릭해야한다는 것을 의미합니다.
활동을 시작하지 않고 알림 만 표시하십시오.

클래스 "Main"과 알람 관리자가 있습니다. 이 알람 관리자는 특정 시간에 시작되어 다른 활동 (DisplayNotification)을 시작합니다. DisplayNotification 클래스에서

{ 
    Intent intent = new Intent("com.test.DisplayNotification"); 
    intent.putExtra("alarm_message", "Alarm"); 
    intent.putExtra("item_name", "message"); 
    PendingIntent broadcast = PendingIntent.getActivity(getBaseContext(), 0, intent, 0); 
    AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE); 
    am.set(AlarmManager.RTC_WAKEUP, mili, broadcast); 
} 


은 내가

public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

     String message = getIntent().getExtras().getString("item_name"); 

     Intent i = new Intent("com.test.Main"); 


     PendingIntent detailsIntent = 
      PendingIntent.getActivity(this, 0, i, 0); 

     NotificationManager nm = (NotificationManager) 
      getSystemService(NOTIFICATION_SERVICE); 
     Notification notif = new Notification(
      R.drawable.icon, 
      "Time's up!", 
      System.currentTimeMillis()); 

     CharSequence from = "AlarmManager - Time's up!"; 
     notif.setLatestEventInfo(this, from, message, detailsIntent); 


     nm.notify(1, notif); 
     //---destroy the activity--- 
     finish(); 

    } 

답변

2

은 그것의 onReceive(...) 방법에 Notification을 만들 수있는 다음 알람의 결과를 '듣기'에 BroadcastReceiver를 사용하고 있습니다.

+0

나는 이것에 대해 생각해 봤지만 문맥을 이해하는데 문제가있다. 그러나 이제는 진흙에서 나를 데려다 주셔서 감사합니다. –

+0

@ Trần Đức Anh : 다행히 도울 수 있어요. – Squonk

관련 문제