相关疑难解决方法(0)

不同的通知声音在Oreo中不起作用

我仅在Oreo版本中面临一些与通知相关的问题。我按照此链接操作,并按照他的建议在卸载/安装应用程序后成功获得了自定义声音。

现在的问题是我想在我的应用程序中使用两种自定义声音,为此,我有如下代码:

private void sendNotification(NotificationBean notificationBean) {
    String textTitle = notificationBean.getTitle();
    String alert = notificationBean.getMessage().getAlert();
    int orderId = notificationBean.getMessage().getOrderId();
    String notificationType = notificationBean.getMessage().getNotificationType();
    String sound = notificationBean.getMessage().getSound();

    Intent intent = new Intent(this, NavigationDrawerActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri soundUri;

    if (notificationType.equals("Pending"))
        soundUri = Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.sound);
    else
        soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, getString(R.string.app_name))
            .setSmallIcon(R.drawable.ic_stat_name)
            .setContentTitle(textTitle)
            .setContentText(alert)
            .setSound(soundUri)
            .setContentIntent(pendingIntent)
            .setPriority(NotificationCompat.PRIORITY_DEFAULT);

    // Create the NotificationChannel, …
Run Code Online (Sandbox Code Playgroud)

android android-notifications android-8.0-oreo

3
推荐指数
2
解决办法
1898
查看次数