频道栏目
IT货架 > > 正文
android如何替换contact的来电铃声
网友分享于:Jan 1, 1970 8:00:00 AM    来源: IT货架   

标签:来电铃声

如果知道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;
    }

bubuko.com,布布扣

android如何替换contact的来电铃声

标签:来电铃声

相关板块推荐 iPhone WindowsPhone

广告服务联系QQ:1134687142 | 网站地图

版权所有: IT货架- 内容来自互联网,仅供用于技术学习,请遵循相关法律法规. 京ICP备11030978号-1