通知声音无法再次尝试-Android Studio

我已经开发了一个Android应用程序,其中使用了opentok视频会议通话功能。我正在通过Firebase推送通知获取视频通话通知。但是,当我第一次安装应用程序时,它会在通知中发出声音,然后当我接受并进入另一个活动的视频会议屏幕后,在下次通话通知时,它只会振动而不会响起声音。

下面是我的通知代码段:

MyFirebaseMessagingServie.class

    private void sendCallNotification(int status,String message,int queryId) {
        saveNotificationLog(status,queryId);
        long[] vibrate = new long[]{1000,1000,1000};
        final UserManager userManager = new UserManager(getapplicationContext());
        boolean isLoggedIn = userManager.isLoggedIn().get();
        Intent notificationIntent = isLoggedIn ? new Intent(this,HomeDoctorView.class) : new Intent(this,LoginView.class);
        if (status == 6 || status == 7) {
            notificationIntent.putExtra(Params.INTENT.SHOULD_UDPATE,true);
        }
        notificationIntent.setaction(Intent.actION_MAIN);
        notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        notificationIntent.addflags(Intent.flaG_actIVITY_NEW_TASK);
        Uri defaultsoundUri = Uri.parse("android.resource://com.myapplication.app/" + R.raw.iphone_ringtone);
        Utils.printLog("FireBaseMessagingService",defaultsoundUri.toString());
        PendingIntent pendingIntent = PendingIntent.getactivity(this,notificationIntent,0);

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,CALL_CHANNEL)
                .setContentTitle(getString(R.string.app_name))
                .setContentText(message)
                .setsound(defaultsoundUri)
                .setVibrate(vibrate)
                .setautoCancel(false)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setPriority(NotificationCompat.PRIORITY_MAX)
                .setContentIntent(pendingIntent);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLlipoP) {
            notificationBuilder.setSmallIcon(R.drawable.ic_notification);
            notificationBuilder.setColor(ContextCompat.getcolor(this,R.color.cerulean));
        } else {
            notificationBuilder.setSmallIcon(R.drawable.ic_notification);
        }

        Notificationmanager notificationmanager = (Notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            if (notificationmanager.getNotificationChannel(CALL_CHANNEL) == null) {
                notificationmanager.createNotificationChannel(Utils.createNotifChannel(this,defaultsoundUri,CALL_CHANNEL));
            }
        }
        notificationmanager.notify(notificationId,notificationBuilder.build());
    }

Utils.java

@RequiresApi(Build.VERSION_CODES.O)
    public static NotificationChannel createNotifChannel(Context context,Uri defaultsoundUri,String channelId) {
        String channelName = channelId.equals("call_channel") ? "Call Alerts" : "Notification Alerts";
        NotificationChannel channel = new NotificationChannel(channelId,channelName,Notificationmanager.IMPORTANCE_HIGH);
        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
                .build();
        if (channelId.equals("call_channel")) {
            channel.setDescription("Alerts related to calls");
            channel.setVibrationPattern(new long[]{1000,1000});
            channel.setBypassDnd(true);
            channel.setsound(defaultsoundUri,audioAttributes);
            channel.enableVibration(true);
            channel.enableLights(true);
            channel.setShowBadge(false);
        } else {
            channel.setDescription("Alerts related to prescription,scheduled appointments,etc.");
            channel.setVibrationPattern(new long[]{500,500,500});
            channel.setBypassDnd(true);
            channel.setsound(defaultsoundUri,audioAttributes);
            channel.enableVibration(true);
            channel.enableLights(true);
            channel.setShowBadge(false);
        }
        Notificationmanager manager = context.getSystemService(Notificationmanager.class);
        manager.createNotificationChannel(channel);
        Log.d("CHANNEL","createNotifChannel: created " + channelId + "\n" + defaultsoundUri);
        return channel;
    }
ief111111 回答:通知声音无法再次尝试-Android Studio

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3060592.html

大家都在问