2014-01-10 236 views
0

我使用報警經理及彼本地通知待定意圖是我的代碼,它完美地運行,所有報警和通知在適當的時候來了。但我想,當我點擊通知它應該去Act_Remainder類在我的應用程序。 如何解決這個問題?報警管理器(通知)

Intent intent1 = newIntent(this.getApplicationContext(), Act_Remainder.class); 

    if(intent!=null){ 
     userID = intent.getStringExtra("UserID"); 
     userID1 = intent.getStringExtra("UserID1"); 
     ID = intent.getIntExtra("ID", 0); 
    } 

    Notification notification = new Notification(R.drawable.ioc_icon, 
    userID1, System.currentTimeMillis()); 

    intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); 

PendingIntent pendingNotificationIntent =  PendingIntent.getActivity(this.getApplicationContext(), 0, intent1, PendingIntent.FLAG_ONE_SHOT); 


notification.flags |= Notification.FLAG_AUTO_CANCEL; 
+0

Thannx所有編輯我的問題,但任何人都可以幫我解決這個問題????????? – krishna

+0

replce PendingIntent.FLAG_ONE_SHOT to PendingIntent.FLAG_UPDATE_CURRENT –

+0

@Lucky我也試過這個,但它在未知的時間發送一個空白通知,意味着1小時或半小時之後......這個時間不確定 – krishna

回答

1

或者乾脆用這個...

公共無效在onStart(意向意圖,詮釋startId){ super.onStart(意向,startId);

mManager = (NotificationManager) this.getApplicationContext() 
      .getSystemService(      this.getApplicationContext().NOTIFICATION_SERVICE); 

    Intent intent1 = new Intent(this.getApplicationContext(),Act_DashBord.class); 
Notification notification = new Notification(R.drawable.applogo_57x57, 
      "Muslim Companion", System.currentTimeMillis()); 

    intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP 
      | Intent.FLAG_ACTIVITY_CLEAR_TOP); 

    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
      this.getApplicationContext(), 0, intent1,PendingIntent.FLAG_UPDATE_CURRENT); 


    notification.flags |= Notification.FLAG_AUTO_CANCEL; 

    int id = 0; 
    if (intent != null) { 
    String message = intent.getStringExtra("Message"); 
     id = intent.getIntExtra("Id", 0); 
    }   

      notification.setLatestEventInfo(this.getApplicationContext(), 
      "Muslim Companion", message, pendingNotificationIntent); 
    long count = System.currentTimeMillis(); 
    mManager.notify(Integer.valueOf(id), notification); 


    mManager.cancel(Integer.valueOf(id)); 

} 
+0

感謝名單就IM解決我的問題.. – krishna

+0

感謝您的編輯,它是我工作區中的複製和粘貼問題。 –