Android通知触摸打开活动不起作用

时间:2019-12-27 14:46:52

标签: android notifications

上下文:-

我正在构建呼叫应用程序。传入呼叫时,用户会收到抬头通知,而在触摸时会打开pendingintent,但它不起作用。

我在SO上搜索的内容:

How can I open activity when notification is touched?

但是我已经有一个与构建器相关的未决意图。.

android How to start activity when user clicks a notification?

不起作用

我编写的代码:

manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    Bitmap IconLg = BitmapFactory.decodeResource(context.getResources(), R.drawable.insta_logo);

Intent Dialer = new Intent(context, DialerActivity.class);
Dialer.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Dialer.putExtra("phoneNumber", phoneNumber);

PendingIntent pendingIntent = PendingIntent.getService(context, 0 , Dialer, PendingIntent.FLAG_UPDATE_CURRENT);

Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

mBuilder = new NotificationCompat.Builder(context, Notification_Channel_Id);

mBuilder.setContentTitle("Incoming Call");
mBuilder.setContentText(phoneNumber);

mBuilder.setSound(alarmSound);
mBuilder.setLargeIcon(IconLg);
mBuilder.setSmallIcon(R.drawable.ic_call_black_24dp);
mBuilder.setAutoCancel(false);
mBuilder.setOngoing(true);

mBuilder.setPriority(NotificationCompat.PRIORITY_MAX);
mBuilder.setContentIntent(pendingIntent);

mBuilder.setChannelId(Notification_Channel_Id);

notification = mBuilder.build();

notification.defaults = Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE;

manager.notify(22, notification);

提前谢谢

0 个答案:

没有答案