Это мое уведомление, мне нужно событие при нажатии кнопки при уведомлении. setOnClickPendingIntent не работает для меня. R.layout.mynotification находится под кодом. (Я не хочу addAction).Нажатие кнопки пользовательского уведомления
Intent intent = new Intent(Fragmentz.ctx, NotificationReceiverActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(Fragmentz.ctx, (int) System.currentTimeMillis(), intent, 0);
// Build notification
RemoteViews notificationView = new RemoteViews(Fragmentz.ctx.getPackageName(),
R.layout.mynotification);
Notification noti = new Notification.Builder(Fragmentz.ctx)
.setContentTitle("Radio")
.setContentText("").setSmallIcon(R.drawable.logo_notif)
.setContentIntent(pIntent)
.build();
noti.contentView = notificationView;
NotificationManager notificationManager = (NotificationManager) Fragmentz.ctx.getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, noti);
R.layout.mynotification.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="100" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:text="Play"
android:id="@+id/not_button"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="@drawable/img_btn_play"
android:background="@null"
/>
</LinearLayout>
Смотрите, если мой ответ работает для вас. – Rohit5k2