私は2つのデバイスを持っています。 1つはAPI 26を実行しており、もう1つはAPI 21です。私はGoogleのfirebaseを使って通知しています。 API 26デバイスは、まずアプリを開くまでプッシュ通知を受け取りません。その後、それはすべてうまく受信します。 API 27デバイスのプッシュ通知を受け取るために、まずアプリケーションを開く必要はありません。アプリを開かなくてもいつもプッシュを受け取る方法についての考えはありますか?自分の電話をオンにするだけで通知がユーザーに届きたい。アプリがAndroidで閉じられているとプッシュ通知が表示されない
private void sendNotification(String title, String messageBody, String clickAction) {
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String id = "";
if (Build.VERSION.SDK_INT >= 26) {
id = "my_channel_01";
// The user-visible name of the channel.
CharSequence name = "myChannel";
// The user-visible description of the channel.
String description = "";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = new NotificationChannel(id, name,importance);
// Configure the notification channel.
mChannel.setDescription(description);
mChannel.enableLights(true);
// Sets the notification light color for notifications posted to this
// channel, if the device supports this feature.
mChannel.setLightColor(Color.RED);
mChannel.enableVibration(true);
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
notificationManager.createNotificationChannel(mChannel);
}
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
String channelId = getString(R.string.default_notification_channel_id);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, id)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
notificationManager.notify(1 /* ID of notification */, notificationBuilder.build());
}
firebaseからの通知をどのように送信しましたか?コンソールかAPIか? – zihadrizkyef
api – RobOhRob