Я искал BroadcastReceiver
намеренное прохождение, но безрезультатно. Я создаю приложение, которое запрашивает ответ в уведомлении, но всякий раз, когда я нажимаю на кнопку добавления действия в уведомлении, я не могу получить log.i
из BroadcastReceiver
. Какие-нибудь советы?
NotificationService. java:
public void displayNotification() {
Log.i("NotificationService", "NotificationService test");
Intent intent = new Intent(this.reactContext, com.uzskaite.MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
Uri uri = intent.getData();
Intent broadcastIntent = new Intent(this.reactContext, com.uzskaite.MyIntentService.class);
broadcastIntent.putExtra("toastMessage", "pidars");
//Yes intent
Intent yesAnswer = new Intent(this.reactContext, ActionReceiver.class);
yesReceive.setAction("YES_ACTION");
PendingIntent pendingIntentYes = PendingIntent.getBroadcast(this.reactContext, 12345, yesAnswer PendingIntent.FLAG_UPDATE_CURRENT);
// mBuilder.addAction(17301575, "Yes", pendingIntentYes);
//No intent
Intent noAnswer = new Intent(this.reactContext, com.notifications.ActionReceiver.class);
noReceive.setAction("NO_ACTION");
PendingIntent pendingIntentNo = PendingIntent.getBroadcast(this.reactContext, 12345, noAnswer, PendingIntent.FLAG_UPDATE_CURRENT);
// mBuilder.addAction(17301575, "No", pendingIntentNo);
PendingIntent pendingIntent = PendingIntent.getActivity(this.reactContext, 0, intent, 0);
String CHANNEL_ID = "notificationsChannel";
NotificationCompat.Builder builder = new NotificationCompat.Builder(this.reactContext, CHANNEL_ID);
builder.addAction(17301575, "Yes", pendingIntentYes);
builder.addAction(17301575, "No", pendingIntentNo);
builder.setSmallIcon(17301575);
builder.setContentTitle("Notifiks");
builder.setContentText("Narmal teksts");
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
builder.setContentIntent(pendingIntentYes);
builder.setAutoCancel(true);
// builder.setOngoing(true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this.reactContext);
notificationManager.notify(123, builder.build());
}
private void createNotificationChannel() {
String CHANNEL_ID = "notificationsChannel";
CharSequence name = new StringBuffer("charsequence");
String description = "kkads apraksts";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
NotificationManager notificationManager = this.reactContext.getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
}
ActionReceiver. java (BroadcastReceiver
):
public class ActionReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
String YES_ACTION = "YES_ACTION";
String NO_ACTION = "YES_ACTION";
Log.v("NotificationService","Pressed ZUPP");
if(YES_ACTION.equals(action)) {
Log.v("NotificationService","Pressed YES");
} else if(NO_ACTION.equals(action)) {
Log.v("NotificationService","Pressed MAYBE");
}
}
}