2012-05-30 128 views
1

推出的活動我有調度的通知下面的代碼...安卓:無法從通知

private void publishNotification(Intent intent, String header, String content){ 
     try { 
      NotificationManager manager = getNotificationManager(); 
      Notification notification = new Notification(R.drawable.droid, header, System.currentTimeMillis()); 

      if(intent != null){ 
       PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); 
       notification.setLatestEventInfo(this, header, content, pendingIntent); 
      } 

      manager.notify(0, notification); 

     } catch (Exception ex) { 
      FileManager.writeToLogFile(this.getClass(), "publishNotification", LogMessageType.ERROR, ex.getMessage()); 
     } 
    } 

而下面的代碼就可以調用...

Intent intent = new Intent(); 
       intent.setAction(DevicePolicyManager.ACTION_SET_NEW_PASSWORD); 
       intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
       publishNotification(intent, "Default Password Changed", "Device configuration have changed.\nClick here to change this password."); 

我的問題如下所示...

該通知出現在通知中,甚至在滑下之後。問題是,當我點擊這個通知時,活動不會啓動。我想我已經完成了tutorial中提到的所有內容。我究竟做錯了什麼 ?

回答

4

如果要啓動某個活動,應該使用PendingIntent.getActivity()而不是PendingIntent.getService()

2
Intent intent = new Intent(context, class_name.class); 
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 

,還可以使用PendingIntent.getActivity()代替PendingIntent.getService()