ورود

View Full Version : مشکل با تنظیم Ringtone



ho3ein.3ven
جمعه 10 مرداد 1393, 11:18 صبح
سلام .

من می خوام رینگتون گوشی رو تغییر بدم . برای این کار میام از تابعی که توی این هم کد گذاشته شده استفاده می کنم ولی جواب نمیده .

تابع :

public boolean saveasring(int type , int Sound) { byte[] buffer = null;
InputStream fIn = getBaseContext().getResources().openRawResource(
Sound);
int size = 0;

try {
size = fIn.available();
buffer = new byte[size];
fIn.read(buffer);
fIn.close();
} catch (IOException e) {
return false;
}

String path = Environment.getExternalStorageDirectory().getPath( )
+ "/media/audio/ringtones/";

String filename = "zang1.mp3";

boolean exists = (new File(path)).exists();
if (!exists) {
new File(path).mkdirs();
}

FileOutputStream save;
try {
save = new FileOutputStream(path + filename);
save.write(buffer);
save.flush();
save.close();
} catch (FileNotFoundException e) {
return false;
} catch (IOException e) {
return false;
}

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
Uri.parse("file://" + path + filename)));

File k = new File(path, filename);

ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, filename);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");

// This method allows to change Notification and Alarm tone also. Just
// pass corresponding type as parameter
if (RingtoneManager.TYPE_RINGTONE == type) {
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
} else if (RingtoneManager.TYPE_NOTIFICATION == type) {
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, true);
} else if (RingtoneManager.TYPE_ALARM == type) {
values.put(MediaStore.Audio.Media.IS_ALARM, true);
}

Uri uri = MediaStore.Audio.Media.getContentUriForPath(k
.getAbsolutePath());
Uri newUri = this.getContentResolver().insert(uri, values);
RingtoneManager.setActualDefaultRingtoneUri(this, type,
newUri);

// Insert it into the database
this.getContentResolver()
.insert(MediaStore.Audio.Media.getContentUriForPat h(k
.getAbsolutePath()), values);



return true;
}


فراخوانی :


saveasring(RingtoneManager.TYPE_RINGTONE,musicid);


کسی می تونه راهنمایی کنه که چرا جواب نمیده .

ho3ein.3ven
جمعه 10 مرداد 1393, 14:08 عصر
کسی نمیتونه کمک کنه؟

hossein_pa
جمعه 03 اردیبهشت 1395, 20:50 عصر
از این کد استفاده کن:

File k = new File("path"); // path is a file playing
ContentValues values = new ContentValues();
values.put(MediaStore.MediaColumns.DATA, k.getAbsolutePath());
values.put(MediaStore.MediaColumns.TITLE, "khorshide hashtom"); //You will have to populate
values.put(MediaStore.MediaColumns.SIZE, 215454);
values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mp3");
values.put(MediaStore.Audio.Media.ARTIST, R.string.app_name); //You will have to populate this
values.put(MediaStore.Audio.Media.DURATION, 230);
values.put(MediaStore.Audio.Media.IS_RINGTONE, true);
values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false);
values.put(MediaStore.Audio.Media.IS_ALARM, false);
values.put(MediaStore.Audio.Media.IS_MUSIC, false);

//Insert it into the database
Uri uri = MediaStore.Audio.Media.getContentUriForPath(k.getA bsolutePath());
getContentResolver().delete(uri, MediaStore.MediaColumns.DATA + "=\"" + k.getAbsolutePath() + "\"", null);
Uri newUri = getContentResolver().insert(uri, values);

RingtoneManager.setActualDefaultRingtoneUri(
MusicPlayActivity.this,
RingtoneManager.TYPE_RINGTONE,
newUri

);