首页 > 代码库 > android如何替换contact的来电铃声
android如何替换contact的来电铃声
如果知道contactId,那么可以这样获取已有的ringtone:
public String getContactRington(long contactId) { String rington = ""; String[] projection = { ContactsContract.Contacts.CUSTOM_RINGTONE }; Uri contactUri = ContentUris.withAppendedId( ContactsContract.Contacts.CONTENT_URI, contactId); Cursor cursor = this.getContentResolver().query(contactUri, projection, null, null, null); if (cursor == null) { return rington; } while (cursor.moveToNext()) { rington = cursor.getString(0); break; } cursor.close(); return rington; }
用以下代码可以去调用系统接口改变铃声:
private void doPickRingtone(String ringtones) { Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE); intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false); try { Uri ringtoneUri; if (ringtones != null && ringtones.length() > 0) { ringtoneUri = Uri.parse(ringtones); } else { ringtoneUri = RingtoneManager .getDefaultUri(RingtoneManager.TYPE_RINGTONE); } intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtoneUri); startActivityForResult(intent, RESUTL_RINGTONE_PICKED); } catch (Exception ex) { MktLog.i(TAG,"doPickRingtone:" + ex.toString()); } }
选择铃声完点击确认:
private void handleRingtonePicked(Uri pickedUri) { updateContactRington(mContactId,pickedUri.toString()); } public boolean updateContactRington(long contactId, String rington) { ContentValues values = new ContentValues(); values.put(ContactsContract.Contacts.CUSTOM_RINGTONE, rington); Uri contactUri = ContentUris.withAppendedId( ContactsContract.Contacts.CONTENT_URI, contactId); this.getContentResolver().update(contactUri, values, null, null); return true; }
android如何替换contact的来电铃声
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。