我正在关注Android Dev教程,以便使用Big View
进行通知。在点击按钮时单击通知正文和其他功能时,我想要一个on going
通知功能。
这是我的代码:
Intent bodyIntent = new Intent(context, MainActivity.class);
innerIntent.putExtra(NOTIFICATION_BODY, "Click on notification body");
PendingIntent bodyPendingIntent = PendingIntent.getActivity(context, 0, bodyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent buttonIntent = new Intent(context, MainActivity.class);
buttonIntent.setAction(NOTIFICATION_BUTTON);
PendingIntent buttonPendingIntent = PendingIntent.getService(context, 0, buttonIntent, 0);
android.support.v4.app.NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setCategory(Notification.CATEGORY_SERVICE)
.setPriority(Notification.PRIORITY_MAX)
.setVisibility(Notification.VISIBILITY_PRIVATE)
.setContentIntent(notificationPendingIntent)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.setLights(getResources().getColor(R.color.primary), 50, 10000)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setVibrate(new long[] {0, 50})
.setOngoing(true)
.setStyle(new NotificationCompat.BigTextStyle().bigText("Hello World BIG!"))
.addAction(R.mipmap.ic_image, "Button", buttonPendingIntent);
int mNotificationId = 001;
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, mBuilder.build());
然后在onResume
:
Intent intent = getIntent();
Log.e("m", String.valueOf(intent.getIntExtra(NOTIFICATION_RESULT, 0)));
Log.e("m", String.valueOf(intent.getAction()));
结果:
点击通知正文时bodyIntent
会触发,我会得到正确的log
打印。
点击按钮时:没有任何反应,MainActivity
甚至没有开始。
谢谢,
答案 0 :(得分:2)
如果您要开始某项活动,则应拨打{
"jobs" : [
{
"name" : "Test Build",
"url" : "URL",
"lastBuild" : {
"actions" : [
{
"causes" : [
{
"shortDescription" : "Started by user XXX"
}
]
},
{
"causes" : [
{
"shortDescription" : "Rebuilds build #2"
}
]
},
{
"parameters" : [
{
"name" : "ENVIRONMENT",
"value" : "PROD"
},
{
"name" : "RELEASE"
}
]
}
],
"building" : false,
"duration" : 126580,
"estimatedDuration" : 74509,
"number" : 3,
"timestamp" : 1445261252000,
"url" : "URL",
"builtOn" : "D-slave"
}
},
方法,但是要通过调用PendingIntent.getActivity()
创建buttonPendingIntent
。