手机锁定时不会创建通知声音



我正在开发聊天应用程序,并且正在使用firebase云消息传递。通知正常工作。手机锁定后,通知会正确接收,但不会产生声音。

任何帮助都将不胜感激。

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());
    }
}

转到FCM控制台,启用声音并定义键'sound'==>'默认值';然后转到php Cansole,然后键入以下代码'sound'==>'default';,多数民众赞成

相关内容

  • 没有找到相关文章

最新更新