【问题标题】:Android Notification Sound Not Ringing From Internal MemoryAndroid 通知声音未从内部存储器响起
【发布时间】:2013-09-11 06:00:45
【问题描述】:


历史: 我从网络服务器下载铃声,如果安装了 SD 卡,我将该文件保存到 SD 卡路径,例如 mnt/sdcard/.my_folder_name/abc.mp3 ELSE 使用 context.getFilesDir() 保存到内部存储器,例如 data/data/my .package.name/abc.mp3

问题: 我在通知栏中触发 Android 通知,通知工作正常,但是当我从内部存储器设置 NOTIFICATION SOUND URI 时出现问题,它不播放声音。

在外部存储的情况下,工作正常并播放声音

ringtoneUri = Uri.parse("file:///mnt/sdcard/.my_folder_name/abc.mp3");

notification.sound = ringtoneUri;         

notification.flags |= Notification.FLAG_AUTO_CANCEL;

notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;

notificationManager.notify(1, notification);



在内部存储的情况下,不播放声音我检查了文件,它存在那里

ringtoneUri = Uri.parse(context.getFilesDir().getPath()+"/abc.mp3");

//data/data/my.package.name/files/abc.mp3

notification.sound = ringtoneUri;         

notification.flags |= Notification.FLAG_AUTO_CANCEL;

notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;

notificationManager.notify(1, notification);


我做错了吗???
问候,

【问题讨论】:

  • 没有答案?? :( 它的紧急...

标签: android notifications audio


【解决方案1】:

问题是,通知不支持使用内部存储。 您需要向该音频文件添加公共权限。

File file = new File(context.getFilesDir().getPath()+"/abc.mp3");
file.setReadable(true, false);
ringtoneUri = Uri.parse(context.getFilesDir().getPath()+"/abc.mp3");
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
notificationManager.notify(1, notification);

...
谢谢
萨利克

【讨论】:

    【解决方案2】:

    我会检查权限。每个应用程序都是一个用户。是否所有用户都有权阅读该文件(可能还有随附的文件夹)?

    【讨论】:

    • 喜欢什么权限?
    • 如果我使用媒体播放器库播放它允许我从数据/数据文件夹播放
    • 文件权限,如adb shell ls -l /mnt/sdcard/ 向您展示。
    • 权限被拒绝给我..但是解决方案是什么?
    • 设置权限,File.setReadable()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-24
    • 1970-01-01
    • 2020-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多