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);
کسی می تونه راهنمایی کنه که چرا جواب نمیده .
من می خوام رینگتون گوشی رو تغییر بدم . برای این کار میام از تابعی که توی این هم کد گذاشته شده استفاده می کنم ولی جواب نمیده .
تابع :
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);
کسی می تونه راهنمایی کنه که چرا جواب نمیده .