Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 自定义通知中的一次单击按钮不起作用_Android_Notifications_Android Notifications_Remoteview_Custom Notification - Fatal编程技术网

Android 自定义通知中的一次单击按钮不起作用

Android 自定义通知中的一次单击按钮不起作用,android,notifications,android-notifications,remoteview,custom-notification,Android,Notifications,Android Notifications,Remoteview,Custom Notification,我的通知中有一个暂停按钮,单击该按钮应转到广播接收器。以下是我的代码: NotificationCompat.Builder builder = new NotificationCompat.Builder(WalkTrackingActivity.this); remoteViews = new RemoteViews(getPackageName(), R.layout.content_user_manual); remoteViews.setChronometer(R.id.chronom

我的通知中有一个暂停按钮,单击该按钮应转到广播接收器。以下是我的代码:

NotificationCompat.Builder builder = new NotificationCompat.Builder(WalkTrackingActivity.this);
remoteViews = new RemoteViews(getPackageName(), R.layout.content_user_manual);
remoteViews.setChronometer(R.id.chronometer, SystemClock.elapsedRealtime(), null, false);

Intent intent = new Intent(WalkTrackingActivity.this, WalkTrackingActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(WalkTrackingActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Intent fillInIntent = new Intent(this, pauseButtonListener.class);
fillInIntent.setPackage(getPackageName());
fillInIntent.setAction("PAUSE");
PendingIntent templateIntent = PendingIntent.getBroadcast(this, 0, fillInIntent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setPendingIntentTemplate(R.layout.content_user_manual, templateIntent);
RemoteViews btnView=new RemoteViews (getPackageName(),R.id.imageButton5);
btnView.setOnClickFillInIntent(R.id.imageButton5, fillInIntent);



notification = builder
        .setSmallIcon(getNotificationIcon())
        .setContentIntent(pendingIntent)
        .setAutoCancel(true)
        .setOnlyAlertOnce(true)
        .setContent(remoteViews)
        .build();
notification.flags = Notification.FLAG_ONGOING_EVENT;
notificationManager = (NotificationManager)
        WalkTrackingActivity.this.getSystemService(Context.NOTIFICATION_SERVICE);


notificationManager.notify(0, notification);

我已经在舱单中注册了我的listner。但它仍然不起作用。请帮忙

当您使用自定义通知时,为什么要使用NotificationCompat.Builder?请检查此问题的第一个答案:为什么我们不能将NotificationCompat.Builder与自定义通知一起使用?你是否检查了我第二条评论中提到的链接?是的,我检查了链接。但是,如果不使用Builder,则无法设置小图标。。。。。notification.icon已弃用。那么,如何在不使用builder的情况下实现这一点呢?