首页 > 解决方案 > 监听按钮点击自定义android通知视图

问题描述

我收到了 webView 发出的通知,在通知上我有按钮 A、B、C。

我想要的是听按钮点击,这样我就可以通过browser.loadUrl("javascript:action()");

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mBuilder = new NotificationCompat.Builder(getApplicationContext(), "notify_001");

    contentView = new RemoteViews(getPackageName(), R.layout.custom_push);
    contentView.setImageViewResource(R.id.image, R.drawable.logo_32);
    Intent switchIntent = new Intent(this, myClassName.class);
    PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 1020, switchIntent, 0);

    mBuilder.setSmallIcon(R.drawable.blue);
    mBuilder.setAutoCancel(false);
    mBuilder.setOngoing(true);
    mBuilder.setPriority(Notification.PRIORITY_LOW);
    mBuilder.setOnlyAlertOnce(true);
    mBuilder.build().flags = Notification.FLAG_NO_CLEAR | Notification.PRIORITY_LOW;
    mBuilder.setContent(contentView);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String channelId = "channel_id";
        NotificationChannel channel = new NotificationChannel(channelId, "channel", NotificationManager.IMPORTANCE_LOW);
        channel.setVibrationPattern(new long[]{ 0 });
        channel.enableVibration(false);
        
        notificationManager.createNotificationChannel(channel);
        mBuilder.setChannelId(channelId);
    }
    notification = mBuilder.build();
    notificationManager.notify(NotificationID, notification);

请帮忙。

标签: androidnotificationsonclicklistener

解决方案


推荐阅读