1
私はFCMを使用してプッシュメッセージを出しています。アンドロイドFCMプッシュ、音なし、振動なし、ヘッドアップなし
FCMのウェブサイトにコードをコピー&ペーストすることで、すべてのプッシュメカニズムを実装しました。
これを実行した後、うまく動作するかどうかを何度かテストしました。 Log.d
で確認したところ、プッシュメッセージを受信したときにonMessageReceived
とsendPushNotification
の両方のメソッドがトリガーされることがわかりました。 しかし、メッセージを受信すると、私の電話は音を出さず、振動もなく、頭を上げません。
画面をオンにすると、メッセージが画面に表示されます。
誰でも私にこれらの問題を解決する方法を教えてもらえますか?
public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
private static final String TAG = "FirebaseMsgService";
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// sendPushNotification(remoteMessage.getData().get("message"));
if(remoteMessage.getData().size() > 0){
sendPushNotification(remoteMessage.getNotification().getBody());
}
}
private void sendPushNotification(String message) {
System.out.println("received message : " + message);
Intent intent = new Intent(this, Activity_Login_Main.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 //Request code
, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.backicon).setLargeIcon(BitmapFactory.decodeResource( getResources(),R.mipmap.ic_launcher))
.setContentTitle("Push Title ")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setDefaults(Notification.DEFAULT_SOUND)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wakelock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "TAG");
wakelock.acquire(5000);
notificationManager.notify(0 // ID of notification
, notificationBuilder.build());
}
}
あなたはそれを振動に設定したり、ヘッドアップ通知をするように優先度を 'PRIORITY_HIGH'に設定したりしません。なぜあなたは振動を期待していたのですか? – ianhanniballake
振動を起こして頭を上げる方法を詳しく教えてください。ユーザーは、新しいメッセージが到着したことに気づくことができません。 –