在我的申请表中,我有通知显示。
让我们说当通知显示时我想按“是”进行活动并隐藏通知,按“否”不做任何事情只是隐藏通知。
我尝试了这段代码,但是onclick不是onClckPendingIntent,而是我无法做任何我想做的事。
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.custom_push_layout);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContent(remoteViews)
.setAutoCancel(true);
Intent intent = new Intent(this,GPSTrackingActivity.class);
final Intent yesIntent = new Intent(intent);
final Intent noIntent = new Intent(this, GPSTrackingActivity.class);
TaskStackBuilder yesStackBuilder = TaskStackBuilder.create(this);
yesStackBuilder.addParentStack(MainActivity.class);
yesStackBuilder.addNextIntent(yesIntent);
TaskStackBuilder noStackBuilder = TaskStackBuilder.create(this);
noStackBuilder.addParentStack(MainActivity.class);
noStackBuilder.addNextIntent(noIntent);
PendingIntent yesPendingIntent = yesStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent noPendingIntent = noStackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.btn_yes, yesPendingIntent);
remoteViews.setOnClickPendingIntent(R.id.btn_no, noPendingIntent);
mNotificationManager.notify(100, mBuilder.build());
我怎么能这样做?
答案 0 :(得分:0)
我知道这有点晚了,但我设法通过接收器完成任务。 你应该:
为接收器创建两个意图 -
String SHOULD_OPEN =“should_open_intent” Intent yes = new Intent(this,MyReceiver.class); yes.putBooleanExtra(SHOULD_OPEN,true); 在意图“不”