fm/FMRecord/src/com/codeaurora/fmrecording/FMRecordingService.java
private Uri addToMediaDB(File file) {
        Log.d(TAG, "In addToMediaDB");
        Resources res = getResources();
        ContentValues cv = new ContentValues();
        long current = System.currentTimeMillis();
        long modDate = file.lastModified();
        Date date = new Date(current);
        SimpleDateFormat formatter = new SimpleDateFormat(
                  res.getString(R.string.audio_db_title_format));
        String title = formatter.format(date);

        // Lets label the recorded audio file as NON-MUSIC so that the file
        // won't be displayed automatically, except for in the playlist.
        cv.put(MediaStore.Audio.Media.IS_MUSIC, "1");
        cv.put(MediaStore.Audio.Media.TITLE, title);
        cv.put(MediaStore.Audio.Media.DATA, file.getAbsolutePath());
        cv.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
        cv.put(MediaStore.Audio.Media.DATE_MODIFIED, (int) (modDate / 1000));
        cv.put(MediaStore.Audio.Media.MIME_TYPE, "AUDIO_AAC_MP4");
        cv.put(MediaStore.Audio.Media.ARTIST,
                res.getString(R.string.audio_db_artist_name));
        cv.put(MediaStore.Audio.Media.ALBUM,
                res.getString(R.string.audio_db_album_name));
        Log.d(TAG, "Inserting audio record: " + cv.toString());
        ContentResolver resolver = getContentResolver();
        Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        Log.d(TAG, "ContentURI: " + base);
        Uri result = resolver.insert(base, cv);
        if (result == null) {
            Toast.makeText(this, "Unable to save recorded audio", Toast.LENGTH_SHORT).show();
            return null;
        }
        if (getPlaylistId(res) == -1) {
            createPlaylist(res, resolver);
        }
        int audioId = Integer.valueOf(result.getLastPathSegment());
        addToPlaylist(resolver, audioId, getPlaylistId(res));

        // Notify those applications such as Music listening to the
        // scanner events that a recorded audio file just created.
        sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, result));
        return result;
    }
/*
     * Adds file and returns content uri.
     */
Adds file and returns content uri.
Adds file and returns content uri .
private Uri addToMediaDB(File file) {
        Log.d(TAG, "In addToMediaDB");
        Resources res = getResources();
        ContentValues cv = new ContentValues();
        long current = System.currentTimeMillis();
        long modDate = file.lastModified();
        Date date = new Date(current);
        SimpleDateFormat formatter = new SimpleDateFormat(
                  res.getString(R.string.audio_db_title_format));
        String title = formatter.format(date);
        cv.put(MediaStore.Audio.Media.IS_MUSIC, "1");
        cv.put(MediaStore.Audio.Media.TITLE, title);
        cv.put(MediaStore.Audio.Media.DATA, file.getAbsolutePath());
        cv.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
        cv.put(MediaStore.Audio.Media.DATE_MODIFIED, (int) (modDate / 1000));
        cv.put(MediaStore.Audio.Media.MIME_TYPE, "AUDIO_AAC_MP4");
        cv.put(MediaStore.Audio.Media.ARTIST,
                res.getString(R.string.audio_db_artist_name));
        cv.put(MediaStore.Audio.Media.ALBUM,
                res.getString(R.string.audio_db_album_name));
        Log.d(TAG, "Inserting audio record: " + cv.toString());
        ContentResolver resolver = getContentResolver();
        Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        Log.d(TAG, "ContentURI: " + base);
        Uri result = resolver.insert(base, cv);
        if (result == null) {
            Toast.makeText(this, "Unable to save recorded audio", Toast.LENGTH_SHORT).show();
            return null;
        }
        if (getPlaylistId(res) == -1) {
            createPlaylist(res, resolver);
        }
        int audioId = Integer.valueOf(result.getLastPathSegment());
        addToPlaylist(resolver, audioId, getPlaylistId(res));
        sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, result));
        return result;
    }
private Uri addToMediaDB ( File file ) { Log . d ( TAG , "In addToMediaDB" ) ; Resources res = getResources ( ) ; ContentValues cv = new ContentValues ( ) ; long current = System . currentTimeMillis ( ) ; long modDate = file . lastModified ( ) ; Date date = new Date ( current ) ; SimpleDateFormat formatter = new SimpleDateFormat ( res . getString ( R . string . audio_db_title_format ) ) ; String title = formatter . format ( date ) ; cv . put ( MediaStore . Audio . Media . IS_MUSIC , "1" ) ; cv . put ( MediaStore . Audio . Media . TITLE , title ) ; cv . put ( MediaStore . Audio . Media . DATA , file . getAbsolutePath ( ) ) ; cv . put ( MediaStore . Audio . Media . DATE_ADDED , ( int ) ( current / 1000 ) ) ; cv . put ( MediaStore . Audio . Media . DATE_MODIFIED , ( int ) ( modDate / 1000 ) ) ; cv . put ( MediaStore . Audio . Media . MIME_TYPE , "AUDIO_AAC_MP4" ) ; cv . put ( MediaStore . Audio . Media . ARTIST , res . getString ( R . string . audio_db_artist_name ) ) ; cv . put ( MediaStore . Audio . Media . ALBUM , res . getString ( R . string . audio_db_album_name ) ) ; Log . d ( TAG , "Inserting audio record: " + cv . toString ( ) ) ; ContentResolver resolver = getContentResolver ( ) ; Uri base = MediaStore . Audio . Media . EXTERNAL_CONTENT_URI ; Log . d ( TAG , "ContentURI: " + base ) ; Uri result = resolver . insert ( base , cv ) ; if ( result == null ) { Toast . makeText ( this , "Unable to save recorded audio" , Toast . LENGTH_SHORT ) . show ( ) ; return null ; } if ( getPlaylistId ( res ) == - 1 ) { createPlaylist ( res , resolver ) ; } int audioId = Integer . valueOf ( result . getLastPathSegment ( ) ) ; addToPlaylist ( resolver , audioId , getPlaylistId ( res ) ) ; sendBroadcast ( new Intent ( Intent . ACTION_MEDIA_SCANNER_SCAN_FILE , result ) ) ; return result ; }
Adds file and returns content uri.
Adds file and returns content uri .
// Lets label the recorded audio file as NON-MUSIC so that the file // won't be displayed automatically, except for in the playlist. // Notify those applications such as Music listening to the // scanner events that a recorded audio file just created.