I\'m trying to find a way to set a new default ringtone by code from my Android activity.
I have already downloaded the ringtone into a bytearray
.
I cannot comment the solution because I don't have enough reputation on stack overflow ... I want just add a way to add the audio file into media database without accessing directly to the database and hence avoiding to get duplicates. The solution is based on MediaScannerConnection, this is the code I used:
String[] files = { audioFullPath };
MediaScannerConnection.scanFile(
getApplicationContext(),
files,
null,
new OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
Log.v("myapp", "file " + path + " was scanned seccessfully: " + uri);
}
}
);