Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 高級開發 >> android 個人鈴聲設置代碼

android 個人鈴聲設置代碼

編輯:高級開發

 1、首先選中列表的鈴聲

  Java代碼 收藏代碼

  private void doPickRingtone() {

  Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);

  // Allow user to pick 'Default'

  intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);

  // Show only ringtones

  intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_RINGTONE);

  // Don't show 'Silent'

  intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, false);

  Uri ringtoneUri;

  if (mCustomRingtone != null) {

  ringtoneUri = Uri.parse(mCustomRingtone);

  } else {

  // Otherwise pick default ringtone Uri so that something is selected.

  ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);

  }

  // Put checkmark next to the current ringtone for this contact

  intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, ringtoneUri);

  // Launch!

  startActivityForResult(intent, RINGTONE_PICKED);

  }

  2、選中之後修改數據庫

  Java代碼 收藏代碼

  @Override

  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

  if (resultCode != RESULT_OK) {

  return;

  }

  switch (requestCode) {

  case RINGTONE_PICKED: {

  // 選擇完鈴聲之後獲得選中鈴音的URI,將其值存入數據

  Uri pickedUri = data.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI);

  handleRingtonePicked(pickedUri);

  break;

  }

  }

  }

  private void handleRingtonePicked(Uri pickedUri) {

  if (pickedUri == null || RingtoneManager.isDefault(pickedUri)) {

  mCustomRingtone = null;

  } else {

  mCustomRingtone = pickedUri.toString();

  接上頁

  }

  saveData();

  }

  /**

  * 保存數據

  */

  private void saveData() {

  ContentValues values = new ContentValues();

  values.put(Contacts.CUSTOM_RINGTONE, mCustomRingtone);

  //這裡的mContactId是當前聯系人的Id

  getContentResolver().update(Contacts.CONTENT_URI, values, Contacts._ID + " = " + mContactId, null) ;

  }

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved