Why setOnClickPendingIntent is not working in Android 7.0 Nougat in the notice?

0 like 0 dislike
This code (below) works fine in the API below and above 24. Not only works in Android 7.0 Nougat. Question: why and how to fix it?

Create a custom notification:

We hang the handler on click on the notification area:
RemoteViews remoteViews = new RemoteViews(getPackageName(), R. layout.control_notification); ActionIntent Intent = new Intent(ACTION_NOTIFICATION_BUTTONS); remoteViews.setOnClickPendingIntent(R. id.notify_button, PendingIntent.getBroadcast( this 1, actionIntent, PendingIntent.FLAG_UPDATE_CURRENT )); NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CONTROL_CHANNEL_ID) .setContent(remoteViews) .setSmallIcon(R. drawable.ic_notification) .setPriority(NotificationCompat.PRIORITY_HIGH);

A notification is displayed using startForeground. For clicks on notification under the 7th non-responsive. Checked on the phone and on the emulator.

On stackoverflow there is a similar question, but no solutions. The author's proposed response are added into the markup with the following code got me nowhere.
android:focusable="true" android:clickable="true"
by | 239 views

1 Answer

0 like 0 dislike
Managed to solve the problem.

The bug is clearly visible in emulator where you can do any number of clicks on the same point. The essence of the bug is that sometimes get lost clicks in the area of custom notifications. Are these points where you can bury your indefinitely until you move the mouse. All of this is random.

Looks like this bug is connected with the internal optimization, unnecessary. If the root layout is empty, then it did not hang the click callback using setOnClickPendingIntent. If not empty, the clicks are random.

To remove the bug it is sufficient to add to the layout element of type Button/ImageButton. Just to add, not hanging on him, the handler clicks and then clicks normally earn on all other elements, on which hung setOnClickPendingIntent.

Example of broken markup that fixes it is sufficient to uncomment the ImageButton.
<?xml version="1.0" encoding="utf-8"?>\r\r\r\r\r\r\r\r\r\r\r\r<!--<ImageButton\randroid:layout_width="64dp"\randroid:layout_height="64dp"\randroid:layout_gravity="center"\randroid:layout_margin="0dp"\randroid:padding="0dp"\randroid:src="@drawable/ic_notify_2"/>-->\r\r

Related questions

110,608 questions
257,186 answers
33,546 users