自定义通知声音在Firebase推送通知中不起作用

时间:2019-09-14 16:00:02

标签: android

在我的应用程序中,自定义通知声音不起作用,请帮助我,这是我的代码。我已在原始文件夹中添加了自定义通知,并通过了路径Uri.parse(“ android.resource://” + this.getPackageName( )+“ /” + R.raw.notification),但无法正常工作,请帮助我

public class Message extends FirebaseMessagingService {

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    super.onMessageReceived(remoteMessage);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "channel_id")
            .setContentTitle(remoteMessage.getNotification().getTitle())
            .setContentText(remoteMessage.getNotification().getBody())
            .setPriority(NotificationCompat.PRIORITY_DEFAULT)
            .setStyle(new NotificationCompat.BigTextStyle())
            .setSound(Uri.parse("android.resource://"+ this.getPackageName() + "/" + R.raw.notification))
            .setSmallIcon(R.mipmap.ic_launcher)
            .setAutoCancel(true);

    NotificationManager notificationManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0, notificationBuilder.build());
}}

0 个答案:

没有答案