我如何更改铃声在机器人编程? [英] How can I change the ringtone in android programmatically?

查看:228
本文介绍了我如何更改铃声在机器人编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个应用程序,基于他们的位置(除其他事项外)将改变用户的铃声。

I'm trying to write an app that (among other things) will change the user's ringtone based on their location.

不过,我有困难,从我的应用程序设置我的手机铃声。我已经能够显示手机的铃声列表,并一直在使用下面的code,试图设定铃声:

However, I'm having difficulty setting the ringtone of my phone from within my app. I've been able to display a list of the phone's ringtones, and have been using the following code to try and set the ringtone:

RingtoneManager.setActualDefaultRingtoneUri(applicationContext, 
      RingtoneManager.TYPE_RINGTONE,
      MediaStore.Audio.Media.getContentUriForPath(settings.getRingtoneURI()));

Settings.System.putString(c.getContentResolver(), Settings.System.RINGTONE, 
      settings.getRingtoneURI());

在这里settings.getRingtoneURI()返回一个字符串所需铃声的URI。

where settings.getRingtoneURI() returns a string with the URI of the desired ringtone.

当我运行这个,我收到没有错误,但铃声也不会改变。

When I run this, I receive no errors but the ringtone does not change.

任何意见?

推荐答案

请问您的应用程序的权限android.permission.WRITE_SETTINGS?

Does your app have permission android.permission.WRITE_SETTINGS?

巴里

这篇关于我如何更改铃声在机器人编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆