Set default alarm sound programatically Android

巧了我就是萌 提交于 2021-01-28 19:39:05

问题


I've been trying to define the default alarm sound but with no success! I can sucessfully change the ringtone and the notification sound but the alarm doesn't change at all... I'm using this code for the alarm:

RingtoneManager.setActualDefaultRingtoneUri(getActivity(), RingtoneManager.TYPE_ALARM, Uri.parse(uri+"/"+id));

Many thanks!


回答1:


Try this

 try {
            RingtoneManager.setActualDefaultRingtoneUri(getContext(),
                    RingtoneManager.TYPE_ALARM, newUri);
            Settings.System.putString(mCr, Settings.System.ALARM_ALERT,
                    newUri.toString());
            Toast.makeText(getContext(), "Done", Toast.LENGTH_SHORT).show();

        } catch (Throwable t) {

        }


来源:https://stackoverflow.com/questions/33593690/set-default-alarm-sound-programatically-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!