【问题标题】:PendingIntent Notification (OnClick not launch) 23.0.1PendingIntent 通知(OnClick 未启动)23.0.1
【发布时间】:2015-11-02 08:51:53
【问题描述】:

当我尝试在 23.0.1 版本中单击我的通知时遇到问题(我更新了最新版本)并且我的通知没有被调用,我尝试了一些方法但不起作用。

我做错了什么?

long mId = System.currentTimeMillis();

Intent intent = new Intent(this, FragmentNotif.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
/*intent.setAction(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);*/
/*intent.putExtra("test","test1");*/
//PendingIntent pendingIntent = PendingIntent.getActivity(context, 1, intent , PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent pendingIntent = PendingIntent.getActivity(context, (int)mId , intent , PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent.cancel();
//pendingIntent.FLAG_CANCEL_CURRENT;



NotificationCompat.Builder mBuilder =
                        new NotificationCompat.Builder(this)
                                .setWhen(mId)
                                .setLargeIcon(notificationLargeIconBitmap)//(R.drawable.icona_notificacio)
                                .setSmallIcon(getNotificationIcon())
                                .setContentTitle("XX XX")
                                .setContentText(data.getStringExtra("message"))
                                .setContentIntent(pendingIntent);

请注意,我的课程扩展自:GCMBaseIntentService

【问题讨论】:

标签: android


【解决方案1】:

您尝试更改源代码

nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
PendingIntent intent = PendingIntent.getActivity(
                    your main.this, (int)mId, new Intent(your main.this, your NotificationMessage.class), PendingIntent.FLAG_UPDATE_CURRENT);

Notification notification;
notification = new Notification.Builder(.this)
                    .setContentTitle(title)
                    .setContentText(text)
                    .setSmallIcon(android.R.drawable.ic_input_add)
                    .setLargeIcon(bitmap).setWhen(System.currentTimeMillis())
                    .setSound(Uri.parse(
                            Environment.getExternalStorageDirectory().getPath()+"/.mp3"))
                    .build();

2. NotificationCompat.Builder

Notification = new NotificationCompat.Builder(context)
          .setContentTitle(title)
          .setContentText(text)
          .setTicker("Notification")
          .setWhen(System.currentTimeMillis())
          .setContentIntent(pendingIntent)
          .setDefaults(Notification.DEFAULT_SOUND)
          .setAutoCancel(true)
          .setSmallIcon(R.drawable.ic_launcher)
          .build();

请参考http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html

【讨论】:

  • 你的代码和我的代码一模一样,我需要使用“NotificationCompat.Builder”
猜你喜欢
  • 2018-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多