2017-04-17 15 views
1

私はチャットアプリケーションを開発中で、Firebase Cloud Messagingを使用しています。通知は正常に機能します。電話がロックされると、通知は正しく受信されますが、音声は生成されません。電話がロックされているときに通知音が生成されない

何か助けていただければ幸いです。

FCMMessagingservice.java

package com.synergywebdesigners.nima; 

import android.app.Notification; 
import android.app.NotificationManager; 
import android.app.PendingIntent; 
import android.content.Context; 
import android.content.Intent; 
import android.graphics.Color; 
import android.media.RingtoneManager; 
import android.net.Uri; 
import android.os.PowerManager; 
import android.support.v4.app.NotificationCompat; 
import android.view.View; 
import android.view.WindowManager; 
import com.google.firebase.messaging.FirebaseMessagingService; 
import com.google.firebase.messaging.RemoteMessage; 

import static android.app.Notification.VISIBILITY_PUBLIC; 
import static com.android.volley.VolleyLog.TAG; 


/** 
* Created by Ashish Shahi on 13-04-2017. 
*/ 

public class FcmMessagingService extends FirebaseMessagingService { 

    long[] pattern = {500,500,500,500,500,500,500,500,500}; 
    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 

     PowerManager pm = (PowerManager)getSystemService(
       Context.POWER_SERVICE); 
     PowerManager.WakeLock wl = pm.newWakeLock(
       PowerManager.SCREEN_DIM_WAKE_LOCK 
         | PowerManager.ON_AFTER_RELEASE, 
       TAG); 


     String title = remoteMessage.getNotification().getTitle(); 
     String message = remoteMessage.getNotification().getBody(); 
     Intent intent = new Intent(this, Memberlist.class); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 
       PendingIntent.FLAG_ONE_SHOT); 
     Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       .setSmallIcon(R.mipmap.ic_action_title) 
       .setContentTitle(title) 
       .setContentText(message) 
       .setAutoCancel(true) 
       .setSound(defaultSoundUri) 
       .setContentIntent(pendingIntent) 
       .setDefaults(0) 
       .setLights(Color.RED, 500, 500) 
       .setPriority(Notification.PRIORITY_HIGH) 
       .setOngoing(true) 
       ; 
     wl.acquire(); 
     // ... do work... 
     wl.release(); 
     /*notificationBuilder.setLights(Color.BLUE, 500, 500); 
     long[] pattern = {500,500,500,500,500,500,500,500,500}; 
     notificationBuilder.setVibrate(pattern);*/ 
     notificationBuilder.setStyle(new NotificationCompat.InboxStyle()); 
     NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(0, notificationBuilder.build()); 

    } 
} 
+1

私はあなたの質問を正しく理解しています。 FCMは、デバイス上で通知をプッシュする2つの方法を提供します。 1つはあなたのアプリがフォアグラウンドにあり、もう1つがバックグラウンドにあるときに機能し、両方のケースを処理する必要があるかもしれません。 [link](https://firebase.google.com/docs/cloud-messaging/concept-options) – am110787

+0

を確認してください。この問題を解決するにはどうすればいいですか –

+0

あなたの投稿を最新のコードで編集し、エラーログは何が起こっているかを見ることができます。 –

答えて

0

FCMコンソールにアクセスし、音を有効にして、キー '音' ==> 'デフォルト' を定義。 php cansoleに移動して以下のコードを入力してください。'sound'==>'default';は正常に動作します。

+0

このアイデアのためにありがとうしかし、私はAPIレベル16を使用しているときに問題が1つしかありませんcontext.message表示されません。 –

関連する問題