Я пробовал большинство решений, но все равно я не получаю дополнительные данные при нажатии на уведомление. Я пытался 1 Почему PendingIntent не отправляет обратно мои пользовательские настройки Extras для Intent? 2 Intent.getExtras () всегда возвращает нуль
String itemID = dataSnapshot.child("itemID").getValue(String.class);
Intent intent = new Intent(UserHomeActivity.this, MapsActivity.class);
intent.putExtra("id", itemID);
intent.setAction(itemID);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
int uniqueInt = (int) (System.currentTimeMillis() & 0xfffffff);
PendingIntent pendingIntent = PendingIntent.getActivity(UserHomeActivity.this, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ){
CharSequence name ="001";
NotificationChannel notificationChannel = new NotificationChannel(Channel_ID, name,NotificationManager.IMPORTANCE_HIGH );
notificationChannel.setDescription("This is description");
NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(notificationChannel);
Notification.Builder builder = new Notification.Builder(getApplicationContext(),Channel_ID);
builder.setSmallIcon(R.mipmap.ic_launcher)
.setContentText(text)
.setContentTitle("New Price Added")
.setContentIntent(pendingIntent)
.setPriority(Notification.PRIORITY_DEFAULT);
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());
notificationManagerCompat.notify(001,builder.build());
}else {
Notification.Builder builder = new Notification.Builder(getApplicationContext());
builder.setSmallIcon(R.mipmap.ic_launcher)
.setContentText(text)
.setContentTitle("New Price Added")
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setPriority(Notification.PRIORITY_MAX);
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(getApplicationContext());
notificationManagerCompat.notify(uniqueInt,builder.build());
Вот мой код для получения дополнительных данных
if(extras != null){
// extract the extra-data in the Notification
String msg = extras.getString("id");
String sss = getIntent().getParcelableExtra("id");
Toast.makeText(this, sss+" ids "+msg+ " "+extras.toString(), Toast.LENGTH_SHORT).show();
}
imageButton = findViewById(R.id.call);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent phoneIntent = new Intent(Intent.ACTION_DIAL);
phoneIntent.setData(Uri.parse("tel:0818283848"));
startActivity(phoneIntent);
}
}); ```