Android 通知自定义声音不工作
Android Notification custom sound not working
我在网上搜索并发现一些 post 与在 android 通知上设置声音有关并关注了它们,但在我的情况下,我在 android 通知上获得默认通知声音.这是我的代码:
builder.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification_message));
我也关注了thispost,但是运气不好。
供您参考:我已经使用 MediaPlayer 播放了 URI,然后它工作正常。
我的部分代码:
NotificationCompat.Builder builder = new NotificationCompat.Builder(appContext);
builder.setContentTitle(message.notificationTitle);
builder.setContentText(message.notificationSubtitle);
builder.setTicker(message.notificationTitle);
builder.setSmallIcon(R.drawable.ic_action_inbox);
Uri uri = Uri.parse("android.resource://" + appContext.getPackageName() + "/" + R.raw.notification_message);
builder.setSound(uri);
builder.setVibrate(new long[]{1000, 1000, 1000});
builder.build();
谁能解释一下问题出在哪里。怎么做?我卡住了:(
使用Context.getPackageName()方法获取Application的包名
Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.notification_message)
移除
Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification_message)
抱歉各位。这是我的错误。
我使用了以下行:
builder.setDefaults(Notification.DEFAULT_ALL);
这导致了问题。评论该行修复它。
感谢您的回答:)
我在网上搜索并发现一些 post 与在 android 通知上设置声音有关并关注了它们,但在我的情况下,我在 android 通知上获得默认通知声音.这是我的代码:
builder.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification_message));
我也关注了thispost,但是运气不好。
供您参考:我已经使用 MediaPlayer 播放了 URI,然后它工作正常。
我的部分代码:
NotificationCompat.Builder builder = new NotificationCompat.Builder(appContext);
builder.setContentTitle(message.notificationTitle);
builder.setContentText(message.notificationSubtitle);
builder.setTicker(message.notificationTitle);
builder.setSmallIcon(R.drawable.ic_action_inbox);
Uri uri = Uri.parse("android.resource://" + appContext.getPackageName() + "/" + R.raw.notification_message);
builder.setSound(uri);
builder.setVibrate(new long[]{1000, 1000, 1000});
builder.build();
谁能解释一下问题出在哪里。怎么做?我卡住了:(
使用Context.getPackageName()方法获取Application的包名
Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.notification_message)
移除
Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notification_message)
抱歉各位。这是我的错误。 我使用了以下行:
builder.setDefaults(Notification.DEFAULT_ALL);
这导致了问题。评论该行修复它。
感谢您的回答:)