2012-05-30 4 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.getService() 대신 PendingIntent.getActivity()을 사용해야합니다.

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

또한 PendingIntent.getActivity() 대신 PendingIntent.getService() 사용합니다.