简体   繁体   English

为 Android 应用程序开发向 Ringtonemanager 添加自定义铃声的问题?

[英]Issue with adding custom ringtone to Ringtonemanager for Android app development?

I am trying to add a custom ringtone for my android app.我正在尝试为我的 android 应用程序添加自定义铃声。 All i have done is created a raw folder in res directory and added a mp3 file there as a ringtone using below code.我所做的只是在 res 目录中创建了一个原始文件夹,并使用以下代码在其中添加了一个 mp3 文件作为铃声。 some how only default notification tone from Android app has been played on calling this ringtone.一些如何在调用此铃声时仅播放来自 Android 应用程序的默认通知音。 Any help would be highly appreciated.任何帮助将不胜感激。

private synchronized void startRinging() {私有同步无效 startRinging() {

    try {


        Uri ringtoneUri = Uri.parse("android.resource://" + getPackageName() + "/raw/ringnow.mp3");
        RingtoneManager.setActualDefaultRingtoneUri(
                getApplicationContext(), RingtoneManager.TYPE_RINGTONE, ringtoneUri
        );
        r = RingtoneManager.getRingtone(getApplicationContext(), ringtoneUri);


        if (r != null) {
            r.play();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}


private synchronized void stopRinging() {

   r.stop();

}

也许你不应该在你的 URI 中写“.mp3”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM