0
私はGCMを使用して通知しています。アンドロイドGCMプッシュ、振動なし、音声なし、ヘッドアップなし
私は、アプリケーションサーバーにユーザーにプッシュ通知を送信するよう依頼し、サーバーはそれを行います。
プッシュ通知を受信すると、メッセージが画面によく表示されます。 しかし、それはどんな音や振動もしません。
ので、ここで私はすでに2 が使用する許可(WAKE_LOCK、VIBRATE)Firebase通知を実装するとき、私は似たような状況にされてきた
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());
}
}
: あなたは詳細についてはこれを参照してください
に)(onMessageReceivedをトリガするためにデータメッセージを送信してみてください。私はそれがうまくいくとわかりました... –
アプリがバックグラウンドであればうまくいきますか? –