Реализация кода
@Override
public void onMessageReceived(RemoteMessage RemoteMessage) {
super.onMessageReceived(remoteMessage);
Код: Выделить всё
Map data = remoteMessage.getData();
Bundle bundle = new Bundle();
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra(FROM_PUSH, 1);
intent.putExtras(bundle);
PendingIntent pendingIntent;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {
pendingIntent = PendingIntent.getActivity
(this, 0, intent, PendingIntent.FLAG_MUTABLE);
} else {
pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
Uri defaultSoundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
"://" + getPackageName() +
"/" + R.raw.noti6);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, DEFAULT_CHANNEL_ID);
if (!TextUtils.isEmpty(data.get(TITLE))) {
notificationBuilder.setContentTitle(data.get(TITLE));
}
if (!TextUtils.isEmpty(data.get(TEXT))) {
notificationBuilder.setContentText(data.get(TEXT));
}
notificationBuilder.setAutoCancel(true);
notificationBuilder.setContentIntent(pendingIntent);
notificationBuilder.setSound(defaultSoundUri);
notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
notificationBuilder.setColor(getColor(R.color.colorAccent));
notificationBuilder.setLights(Color.RED, 1000, 300);
notificationBuilder.setSmallIcon(R.mipmap.ic_notif);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build();
NotificationChannel channel = new NotificationChannel(
DEFAULT_CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH
);
channel.setDescription(CHANNEL_DESC);
channel.setShowBadge(true);
channel.canShowBadge();
channel.setImportance(NotificationManager.IMPORTANCE_HIGH);
channel.enableLights(true);
channel.setSound(defaultSoundUri, audioAttributes);
channel.setLightColor(Color.RED);
channel.enableVibration(true);
channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500});
assert notificationManager != null;
notificationManager.createNotificationChannel(channel);
}
assert notificationManager != null;
notificationManager.notify(new Random().nextInt((10000 - 1222) + 1) + 1222, notificationBuilder.build());
Текущая проблема — получение уведомлений со звуком уведомлений устройства по умолчанию.
Желаемый результат — получение уведомлений со специальным звуком уведомлений.
Подробнее здесь: https://stackoverflow.com/questions/786 ... gacy-fcm-a