Android examples for android.media:Audio
save Audio
import java.io.File; import android.content.ContentValues; import android.content.Context; import android.net.Uri; import android.provider.MediaStore; import android.text.TextUtils; import android.util.Log; public class Main { private static String mFileName; /**/*from w ww. ja v a 2s .c o m*/ * * @param ctx * @return The media content Uri to the newly created audio, or null if failed * for any reason. */ private static Uri saveAudio(Context ctx) { File audioFile = new File(mFileName); ContentValues values = new ContentValues(); values.put(MediaStore.MediaColumns.DATA, audioFile.getAbsolutePath()); values.put(MediaStore.MediaColumns.TITLE, ""); values.put(MediaStore.MediaColumns.MIME_TYPE, "audio/mpeg"); values.put(MediaStore.MediaColumns.SIZE, audioFile.length()); values.put(MediaStore.Audio.Media.ARTIST, ""); values.put(MediaStore.Audio.Media.IS_RINGTONE, false); // Now set some extra features it depend on you values.put(MediaStore.Audio.Media.IS_NOTIFICATION, false); values.put(MediaStore.Audio.Media.IS_ALARM, false); values.put(MediaStore.Audio.Media.IS_MUSIC, false); Uri uri = MediaStore.Audio.Media.getContentUriForPath(audioFile.getAbsolutePath()); Uri uri2 = ctx.getContentResolver().insert(uri, values); if (uri2 == null || TextUtils.isEmpty(uri2.toString())) { Log.w("", "Something went wrong while inserting data to content resolver"); } return uri2; } }