2017-01-17 5 views
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()); 
    } 
} 

答えて

0

を追加し、私のコードのコースの です。 問題は、データ部なしでfirebaseコンソールからプッシュ通知を送信したときに、通知メッセージとして受信されたときです。二つの方法(onMessageReceived、sendPushNotification)が動作するかどうか、私はログで確認https://firebase.google.com/docs/cloud-messaging/concept-options

+0

: あなたは詳細についてはこれを参照してください

に)(onMessageReceivedをトリガするためにデータメッセージを送信してみてください。私はそれがうまくいくとわかりました... –

+0

アプリがバックグラウンドであればうまくいきますか? –

関連する問題