我有这个密码
Intent launchIntent = new Intent(context,WidgetAlarmManagerActivity.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, launchIntent, 0);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Nicilis")
.setTicker(messageBody)
.setContentText(messageBody)
.setAutoCancel(true)
.addAction(android.R.drawable.ic_menu_close_clear_cancel, "Cancel Upload", pendingIntent)
.setSound(defaultSoundUri);
NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
操作在通知中,但当我按下它时,没有任何React
多谢了
2条答案
按热度按时间j0pj023g1#
getBroadcast()
返回一个PendingIntent
,该PendingIntent
将在 Package 的Intent
上调用sendBroadcast()
。getActivity()
返回一个PendingIntent
,该PendingIntent
将在 Package 的Intent
上调用startActivity()
。WidgetAlarmManagerActivity
看起来像是一个活动的名称,建议您应将getBroadcast()
替换为getActivity()
。xa9qqrwz2#
我觉得与其
你应该用