2012-05-30 94 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()