-1

我在我的应用程序中设置了一个通知。它工作正常。如果我单击通知,statusbar它将进入我的应用程序。
现在我需要设置一些工作,如果单击通知我可以在哪里设置?单击通知时是否有任何隐式调用的方法?
另外,如果单击该通知,我想删除该通知,该怎么做?

这是我的代码

notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);  
Intent inty=getIntent();
note = new Notification(R.drawable.icon, "New E-mail", System.currentTimeMillis());  
PendingIntent intent = PendingIntent.getActivity(MainActivity.this, 0, inty, 0);  
note.setLatestEventInfo(MainActivity.this, "New E-mail", "You have one unread message.", intent);
notifManager.notify(R.string.search_hint, note); 
4

2 回答 2

1

尝试调用 broadcastReceiver 它可能对您的要求有所帮助,

Intent notificationIntent = new Intent(this, dummy_activity.class);
notificationIntent.setAction("android.intent.action.MAIN");
notificationIntent.addCategory("android.intent.category.LAUNCHER");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                                notificationIntent,
                                PendingIntent.FLAG_UPDATE_CURRENT | 
                                Notification.FLAG_AUTO_CANCEL);

// Now, once this dummy activity starts send a broad cast to your parent activity and finish the pending activity
//remember you need to register your broadcast action here to receive.
BroadcastReceiver call_method = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action_name = intent.getAction();
        if (action_name.equals("call_method")) {
            // call your method here and do what ever you want.
        }
    }
};
registerReceiver(call_method, new IntentFilter("call_method"));
于 2013-03-27T05:29:49.047 回答
1

您可以向意图添加一些额外的数据,然后在您的活动中的 onCreate 和 onNewIntent 方法中查找它。

例如:

inty.putExtra("came from notification", true);

然后,您可以通过传递给 onNewIntent 的意图或使用 getIntent() 在 onCreate 中读取它。

intent.getBooleanExtra("came from notification", false);
于 2013-03-27T04:39:37.943 回答