Android 修改系統來電鈴聲

 

正文

 

 

            	String paths = mCurrentPath + MountPointManager.SEPARATOR
                + mAdapter.getCheckedFileInfoItemsList().get(0).getFileName();
            	settingRingertone(paths);
 private void settingRingertone(String path) {
       ContentValues cv = new ContentValues();
       Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
       
       Cursor cursor = this.getContentResolver().query(uri,
    		   null, MediaStore.MediaColumns.DATA + =?, new String[] { path }, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
       if (cursor.moveToFirst()) {
    	   String _id = cursor.getString(0);
	       cv.put(AudioColumns.IS_RINGTONE, true);
	       cv.put(AudioColumns.IS_MUSIC, true);
	       // Insert the bell library
	       getContentResolver().update(uri, cv,MediaStore.MediaColumns.DATA + =?, new String[] { path });
	       Uri newUri = ContentUris.withAppendedId(uri, Long.valueOf(_id));
	       // Set up the bell
	       RingtoneManager.setActualDefaultRingtoneUri(this,RingtoneManager.TYPE_RINGTONE, newUri );
	       Toast.makeText(this, R.string.ring_set_succeed, Toast.LENGTH_SHORT).show();
      }
     }

如果不成功請檢查_id的值。

 

發佈留言