android.provider.MediaStore.MediaColumns Java Examples

The following examples show how to use android.provider.MediaStore.MediaColumns. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IOHelper.java    From fanfouapp-opensource with Apache License 2.0 6 votes vote down vote up
public static String getRealPathFromURI(final Context context,
        final Uri contentUri) {
    // get path from uri like content://media//
    final Cursor cursor = context.getContentResolver().query(contentUri,
            new String[] { MediaColumns.DATA }, null, null, null);
    String path = null;
    if (cursor != null) {
        final int column_index = cursor
                .getColumnIndexOrThrow(MediaColumns.DATA);
        cursor.moveToFirst();
        path = cursor.getString(column_index);
    } else {
        path = null;
    }
    cursor.close();
    if (path == null) {
        path = contentUri.getPath();
    }
    return path;
}
 
Example #2
Source File: MusicUtils.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
/**
 * @param context
 * @param id
 * @return
 */
public static long[] getSongListForGenre(Context context, long id) {
    String[] projection = new String[] {
        BaseColumns._ID
    };
    StringBuilder selection = new StringBuilder();
    selection.append(AudioColumns.IS_MUSIC + "=1");
    selection.append(" AND " + MediaColumns.TITLE + "!=''");
    Uri uri = Genres.Members.getContentUri(EXTERNAL, id);
    Cursor cursor = context.getContentResolver().query(uri, projection, selection.toString(),
            null, null);
    if (cursor != null) {
        long[] list = getSongListForCursor(cursor);
        cursor.close();
        return list;
    }
    return sEmptyList;
}
 
Example #3
Source File: MediaStoreUtils.java    From FileManager with Apache License 2.0 6 votes vote down vote up
public static Uri getUriFromFile(final String path, Context context) {
    ContentResolver resolver = context.getContentResolver();

    Cursor filecursor = resolver.query(MediaStore.Files.getContentUri("external"),
            new String[]{BaseColumns._ID}, MediaColumns.DATA + " = ?",
            new String[]{path}, MediaColumns.DATE_ADDED + " desc");
    filecursor.moveToFirst();

    if (filecursor.isAfterLast()) {
        filecursor.close();
        ContentValues values = new ContentValues();
        values.put(MediaColumns.DATA, path);
        return resolver.insert(MediaStore.Files.getContentUri("external"), values);
    } else {
        int imageId = filecursor.getInt(filecursor.getColumnIndex(BaseColumns._ID));
        Uri uri = MediaStore.Files.getContentUri("external").buildUpon().appendPath(
                Integer.toString(imageId)).build();
        filecursor.close();
        return uri;
    }
}
 
Example #4
Source File: MusicUtil.java    From LLApp with Apache License 2.0 6 votes vote down vote up
public static List<Playlist> getMp3List(Context context) {
    List<Playlist> list = new ArrayList<Playlist>();

    Cursor cursor = new ResolverSer().getResolverSer().getResover(context).query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, media_info, "",
            null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
    if (cursor != null && cursor.getCount() == 0) {
        final AlertDialog xfdialog = new AlertDialog.Builder(context).setTitle("Tips:").setMessage(context.getResources().getString(R.string.music_no_one)).setPositiveButton(context.getResources().getString(R.string.is_positive), null).create();
        xfdialog.show();
        cursor.close();
        return null;
    }
    while (cursor.moveToNext()) {
        int id = cursor.getInt(cursor.getColumnIndex(BaseColumns._ID));
        int album_id = cursor.getInt(cursor.getColumnIndex(AudioColumns.ALBUM_ID));
        String title = cursor.getString(cursor.getColumnIndex(MediaColumns.TITLE));
        String artist = cursor.getString(cursor.getColumnIndex(AudioColumns.ARTIST));
        int duration = cursor.getInt(cursor.getColumnIndex(AudioColumns.DURATION));
        if (duration > 30000) {
            Playlist playlist = new Playlist(id, title, duration, artist, album_id);
            list.add(playlist);
        }
    }
    cursor.close();
    return list;
}
 
Example #5
Source File: ImageUtils.java    From AndroidWallet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 获取图片路径
 *
 * @param uri
 * @param
 */
public static String getImagePath(Uri uri, Activity context) {

    String[] projection = {MediaColumns.DATA};
    Cursor cursor = context.getContentResolver().query(uri, projection,
            null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int columIndex = cursor.getColumnIndexOrThrow(MediaColumns.DATA);
        String ImagePath = cursor.getString(columIndex);
        cursor.close();
        return ImagePath;
    }

    return uri.toString();
}
 
Example #6
Source File: MusicUtils.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
/**
 * Create a Search Chooser
 */
public static void doSearch(Context mContext, Cursor mCursor, String Type) {
    CharSequence title = null;
    Intent i = new Intent();
    i.setAction(MediaStore.INTENT_ACTION_MEDIA_SEARCH);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    String query = "";

	if ( Type == TYPE_ALBUM ){
		query = mCursor.getString(mCursor.getColumnIndexOrThrow(AlbumColumns.ALBUM));
	}
	else if( Type == TYPE_ARTIST ){
		query = mCursor.getString(mCursor.getColumnIndexOrThrow(ArtistColumns.ARTIST));
	}
	else if( Type == TYPE_GENRE ||  Type == TYPE_PLAYLIST ||  Type == TYPE_SONG ){
		query = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaColumns.TITLE));
	}
    title = "";
    i.putExtra("", query);
    title = title + " " + query;
    title = "Search " + title;
    i.putExtra(SearchManager.QUERY, query);
    mContext.startActivity(Intent.createChooser(i, title));
}
 
Example #7
Source File: DragSortListViewFragment.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    if( mFragmentGroupId != 0 ){
 	menu.add(mFragmentGroupId, PLAY_SELECTION, 0, getResources().getString(R.string.play_all));
     menu.add(mFragmentGroupId, ADD_TO_PLAYLIST, 0, getResources().getString(R.string.add_to_playlist));
     menu.add(mFragmentGroupId, USE_AS_RINGTONE, 0, getResources().getString(R.string.use_as_ringtone));
     menu.add(mFragmentGroupId, REMOVE, 0, R.string.remove);
     menu.add(mFragmentGroupId, SEARCH, 0, getResources().getString(R.string.search));
     AdapterContextMenuInfo mi = (AdapterContextMenuInfo)menuInfo;
     mSelectedPosition = mi.position;
     mCursor.moveToPosition(mSelectedPosition);
     try {
         mSelectedId = mCursor.getLong(mCursor.getColumnIndexOrThrow(mMediaIdColumn));
     } catch (IllegalArgumentException ex) {
         mSelectedId = mi.id;
     }
     String title = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaColumns.TITLE));
     menu.setHeaderTitle(title);
    }
}
 
Example #8
Source File: QuickQueueFragment.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
	String[] projection = new String[] {
            BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ALBUM, AudioColumns.ARTIST,
    };
    StringBuilder selection = new StringBuilder();
    Uri uri = Audio.Media.EXTERNAL_CONTENT_URI;
    String sortOrder = Audio.Media.DEFAULT_SORT_ORDER;
    uri = Audio.Media.EXTERNAL_CONTENT_URI;
    long[] mNowPlaying = MusicUtils.getQueue();
    if (mNowPlaying.length == 0)
        return null;
    selection = new StringBuilder();
    selection.append(BaseColumns._ID + " IN (");
    if (mNowPlaying == null || mNowPlaying.length <= 0)
        return null;
    for (long queue_id : mNowPlaying) {
        selection.append(queue_id + ",");
    }
    selection.deleteCharAt(selection.length() - 1);
    selection.append(")");
	
    return new AddIdCursorLoader(getActivity(), uri, projection, selection.toString(), null,
            sortOrder);
}
 
Example #9
Source File: QuickQueueFragment.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
/**
 * Reload the queue after we remove a track
 */
private void reloadQueueCursor() {
    String[] projection = new String[] {
            BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ALBUM, AudioColumns.ARTIST,
    };
    StringBuilder selection = new StringBuilder();
    Uri uri = Audio.Media.EXTERNAL_CONTENT_URI;
    String sortOrder = Audio.Media.DEFAULT_SORT_ORDER;
    uri = Audio.Media.EXTERNAL_CONTENT_URI;
    long[] mNowPlaying = MusicUtils.getQueue();
    if (mNowPlaying.length == 0)
        return;
    selection = new StringBuilder();
    selection.append(BaseColumns._ID + " IN (");
    if (mNowPlaying == null || mNowPlaying.length <= 0)
        return;
    for (long queue_id : mNowPlaying) {
        selection.append(queue_id + ",");
    }
    selection.deleteCharAt(selection.length() - 1);
    selection.append(")");

    mCursor = MusicUtils.query(getActivity(), uri, projection, selection.toString(), null,
            sortOrder);
    mQuickQueueAdapter.changeCursor(mCursor);
}
 
Example #10
Source File: AlbumListFragment.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
@Override
public void setupFragmentData() {
       mAdapter = new AlbumListAdapter(getActivity(), R.layout.music_listview_items, null,
               								new String[] {}, new int[] {}, 0);
   	mProjection = new String[] {
               BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ALBUM, AudioColumns.ARTIST
       };
       StringBuilder where = new StringBuilder();
       where.append(AudioColumns.IS_MUSIC + "=1")
       					.append(" AND " + MediaColumns.TITLE + " != ''");
       long albumId = getArguments().getLong(BaseColumns._ID);
       where.append(" AND " + AudioColumns.ALBUM_ID + "=" + albumId);
       mWhere = where.toString();        
       mSortOrder = Audio.Media.TRACK + ", " + Audio.Media.DEFAULT_SORT_ORDER;
       mUri = Audio.Media.EXTERNAL_CONTENT_URI;
       mFragmentGroupId = 89;
       mType = TYPE_ALBUM;
       mTitleColumn = MediaColumns.TITLE; 
}
 
Example #11
Source File: RecentlyAddedFragment.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
public void setupFragmentData(){
    mAdapter = new RecentlyAddedAdapter(getActivity(), R.layout.music_listview_items,
            null, new String[] {}, new int[] {}, 0);
	mProjection = new String[] {
            BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ALBUM, AudioColumns.ARTIST
    };
    StringBuilder where = new StringBuilder();
    int X = MusicUtils.getIntPref(getActivity(), NUMWEEKS, 5) * 3600 * 24 * 7;
    where.append(MediaColumns.TITLE + " != ''");
    where.append(" AND " + AudioColumns.IS_MUSIC + "=1");
    where.append(" AND " + MediaColumns.DATE_ADDED + ">"
            + (System.currentTimeMillis() / 1000 - X));
    mWhere = where.toString();
    mSortOrder = MediaColumns.DATE_ADDED + " DESC";
    mUri = Audio.Media.EXTERNAL_CONTENT_URI;
    mTitleColumn = MediaColumns.TITLE;       
}
 
Example #12
Source File: GenreListFragment.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
public void setupFragmentData(){
    mAdapter = new GenreListAdapter(getActivity(), R.layout.music_listview_items, null,
            								new String[] {}, new int[] {}, 0);
	mProjection = new String[] {
            BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ALBUM,
            AudioColumns.ARTIST
    };
    StringBuilder where = new StringBuilder();
    where.append(AudioColumns.IS_MUSIC + "=1").append(
            				" AND " + MediaColumns.TITLE + " != ''");
    mWhere = where.toString();        
    mSortOrder = Genres.Members.DEFAULT_SORT_ORDER;
    mUri = Genres.Members.getContentUri(EXTERNAL, getArguments().getLong(BaseColumns._ID));
    mFragmentGroupId = 3;
    mType = TYPE_GENRE;
    mTitleColumn = MediaColumns.TITLE; 
}
 
Example #13
Source File: AndroidPathUtils.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Get an Uri from an file path.
 *
 * @param path The file path.
 * @return The Uri.
 */
public static Uri getUriFromFile(final String path, final Context c) {
	ContentResolver resolver = c.getContentResolver();

	Cursor filecursor = resolver.query(MediaStore.Files.getContentUri("external"),
									   new String[] {BaseColumns._ID}, MediaColumns.DATA + " = ?",
									   new String[] {path}, MediaColumns.DATE_ADDED + " desc");
	if (filecursor == null) {
		return null;
	}
	filecursor.moveToFirst();

	if (filecursor.isAfterLast()) {
		filecursor.close();
		ContentValues values = new ContentValues();
		values.put(MediaColumns.DATA, path);
		return resolver.insert(MediaStore.Files.getContentUri("external"), values);
	}
	else {
		int imageId = filecursor.getInt(filecursor.getColumnIndex(BaseColumns._ID));
		Uri uri = MediaStore.Files.getContentUri("external").buildUpon().appendPath(
			Integer.toString(imageId)).build();
		filecursor.close();
		return uri;
	}
}
 
Example #14
Source File: ImageHelper.java    From fanfouapp-opensource with Apache License 2.0 6 votes vote down vote up
/**
 * Store a picture that has just been saved to disk in the MediaStore.
 * 
 * @param imageFile
 *            The File of the picture
 * @return The Uri provided by the MediaStore.
 */
public static Uri storePicture(final Context ctx, final File imageFile,
        String imageName) {
    final ContentResolver cr = ctx.getContentResolver();
    imageName = imageName.substring(imageName.lastIndexOf('/') + 1);
    final ContentValues values = new ContentValues(7);
    values.put(MediaColumns.TITLE, imageName);
    values.put(MediaColumns.DISPLAY_NAME, imageName);
    values.put(ImageColumns.DESCRIPTION, "");
    values.put(ImageColumns.DATE_TAKEN, System.currentTimeMillis());
    values.put(MediaColumns.MIME_TYPE, "image/jpeg");
    values.put(ImageColumns.ORIENTATION, 0);
    final File parentFile = imageFile.getParentFile();
    final String path = parentFile.toString().toLowerCase();
    final String name = parentFile.getName().toLowerCase();
    values.put(Images.ImageColumns.BUCKET_ID, path.hashCode());
    values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, name);
    values.put("_data", imageFile.toString());

    final Uri uri = cr.insert(Images.Media.EXTERNAL_CONTENT_URI, values);

    return uri;
}
 
Example #15
Source File: MediaStoreUtils.java    From SimpleExplorer with GNU General Public License v3.0 6 votes vote down vote up
public static Uri getUriFromFile(final String path, Context context) {
    ContentResolver resolver = context.getContentResolver();

    Cursor filecursor = resolver.query(MediaStore.Files.getContentUri("external"),
            new String[]{BaseColumns._ID}, MediaColumns.DATA + " = ?",
            new String[]{path}, MediaColumns.DATE_ADDED + " desc");
    filecursor.moveToFirst();

    if (filecursor.isAfterLast()) {
        filecursor.close();
        ContentValues values = new ContentValues();
        values.put(MediaColumns.DATA, path);
        return resolver.insert(MediaStore.Files.getContentUri("external"), values);
    } else {
        int imageId = filecursor.getInt(filecursor.getColumnIndex(BaseColumns._ID));
        Uri uri = MediaStore.Files.getContentUri("external").buildUpon().appendPath(
                Integer.toString(imageId)).build();
        filecursor.close();
        return uri;
    }
}
 
Example #16
Source File: MediaStoreUtil.java    From Augendiagnose with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get an Uri from an file path.
 *
 * @param path The file path.
 * @return The Uri.
 */
public static Uri getUriFromFile(final String path) {
	ContentResolver resolver = Application.getAppContext().getContentResolver();

	Cursor filecursor = resolver.query(MediaStore.Files.getContentUri("external"),
			new String[]{BaseColumns._ID}, MediaColumns.DATA + " = ?",
			new String[]{path}, MediaColumns.DATE_ADDED + " desc");
	if (filecursor == null) {
		return null;
	}
	filecursor.moveToFirst();

	if (filecursor.isAfterLast()) {
		filecursor.close();
		ContentValues values = new ContentValues();
		values.put(MediaColumns.DATA, path);
		return resolver.insert(MediaStore.Files.getContentUri("external"), values);
	}
	else {
		int imageId = filecursor.getInt(filecursor.getColumnIndex(BaseColumns._ID));
		Uri uri = MediaStore.Files.getContentUri("external").buildUpon().appendPath(
				Integer.toString(imageId)).build();
		filecursor.close();
		return uri;
	}
}
 
Example #17
Source File: UriFileUtils.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
    Cursor cursor = null;
    final String column = MediaColumns.DATA;
    final String[] projection = { column };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
        if (cursor != null && cursor.moveToFirst()) {
            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return null;
}
 
Example #18
Source File: Utils.java    From android-utils with MIT License 6 votes vote down vote up
@Nullable
/**
 * @deprecated Use {@link MediaUtils#createVideoUri(Context)}
 * Creates external content:// scheme uri to save the videos at.
 */
public static Uri createVideoUri(Context ctx) throws IOException {

    if (ctx == null) {
        throw new NullPointerException("Context cannot be null");
    }

    Uri imageUri;

    ContentValues values = new ContentValues();
    values.put(MediaColumns.TITLE, "");
    values.put(ImageColumns.DESCRIPTION, "");
    imageUri = ctx.getContentResolver().insert(Video.Media.EXTERNAL_CONTENT_URI, values);

    return imageUri;
}
 
Example #19
Source File: Utils.java    From android-utils with MIT License 6 votes vote down vote up
@Nullable
/**
 * @deprecated Use {@link MediaUtils#createImageUri(Context)}
 * Creates external content:// scheme uri to save the images at. The image saved at this
 * {@link android.net.Uri} will be visible via the gallery application on the device.
 */
public static Uri createImageUri(Context ctx) throws IOException {

    if (ctx == null) {
        throw new NullPointerException("Context cannot be null");
    }

    Uri imageUri = null;

    ContentValues values = new ContentValues();
    values.put(MediaColumns.TITLE, "");
    values.put(ImageColumns.DESCRIPTION, "");
    imageUri = ctx.getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);

    return imageUri;
}
 
Example #20
Source File: Utils.java    From android-utils with MIT License 6 votes vote down vote up
/**
 * Get the file path from the Media Content Uri for video, audio or images.
 *
 * @param mediaContentUri Media content Uri.
 **/
public static String getPathForMediaUri(Context context, Uri mediaContentUri) {

    Cursor cur = null;
    String path = null;

    try {
        String[] projection = {MediaColumns.DATA};
        cur = context.getContentResolver().query(mediaContentUri, projection, null, null, null);

        if (cur != null && cur.getCount() != 0) {
            cur.moveToFirst();
            path = cur.getString(cur.getColumnIndexOrThrow(MediaColumns.DATA));
        }

        // Log.v( TAG, "#getRealPathFromURI Path: " + path );
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cur != null && !cur.isClosed())
            cur.close();
    }

    return path;
}
 
Example #21
Source File: ArtistListFragment.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
@Override
public void setupFragmentData(){
    mAdapter = new ArtistListAdapter(getActivity(), R.layout.music_listview_items, null,
            								new String[] {}, new int[] {}, 0);
	mProjection = new String[] {
            BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ALBUM, AudioColumns.ARTIST
    };
    StringBuilder where = new StringBuilder();
    where.append(AudioColumns.IS_MUSIC + "=1")
    					.append(" AND " + MediaColumns.TITLE + " != ''");
    long artist_id = getArguments().getLong(BaseColumns._ID);
    where.append(" AND " + AudioColumns.ARTIST_ID + "=" + artist_id);
    mWhere = where.toString();        
    mSortOrder = MediaColumns.TITLE;
    mUri = Audio.Media.EXTERNAL_CONTENT_URI;
    mFragmentGroupId = 88;
    mType = TYPE_ARTIST;
    mTitleColumn = MediaColumns.TITLE; 
}
 
Example #22
Source File: NowPlayingFragment.java    From mobile-manager-tool with MIT License 6 votes vote down vote up
@Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
      if (data == null) {
          return;
      }
      long[] mNowPlaying = MusicUtils.getQueue();
  	String[] audioCols = new String[] { BaseColumns._ID, MediaColumns.TITLE, AudioColumns.ARTIST, AudioColumns.ALBUM};
      MatrixCursor playlistCursor = new MatrixCursor(audioCols);
  	for(int i = 0; i < mNowPlaying.length; i++){
  		data.moveToPosition(-1);
  		while (data.moveToNext()) {
              long audioid = data.getLong(data.getColumnIndexOrThrow(BaseColumns._ID));
          	if( audioid == mNowPlaying[i]) {
                  String trackName = data.getString(data.getColumnIndexOrThrow(MediaColumns.TITLE));
                  String artistName = data.getString(data.getColumnIndexOrThrow(AudioColumns.ARTIST));
                  String albumName = data.getString(data.getColumnIndexOrThrow(AudioColumns.ALBUM));
          		playlistCursor.addRow(new Object[] {audioid, trackName, artistName, albumName });
          	}
          }
  	}
      data.close();
mCursor = playlistCursor;
      super.onLoadFinished(loader, playlistCursor);
  }
 
Example #23
Source File: MediaUtils.java    From Android-RTEditor with Apache License 2.0 5 votes vote down vote up
private static String getPathFromUri(Context context, Uri imageUri) {
    String filePath = "";

    if (imageUri.toString().startsWith("content://com.android.gallery3d.provider")) {
        imageUri = Uri.parse(imageUri.toString().replace("com.android.gallery3d", "com.google.android.gallery3d"));
    }

    Cursor cursor = null;
    try {
        String column = MediaColumns.DATA;
        String[] proj = {MediaColumns.DATA};

        cursor = context.getContentResolver().query(imageUri, proj, null, null, null);
        cursor.moveToFirst();

        if (imageUri.toString().startsWith("content://com.google.android.gallery3d")) {
            filePath = imageUri.toString();
        } else {
            filePath = cursor.getString(cursor.getColumnIndexOrThrow(column));
        }
    } catch (Exception ignore) {
        // Google Drive content provider throws an exception that we ignore
        // content://com.google.android.apps.docs.storage
    } finally {
        Helper.closeQuietly(cursor);
    }

    if (isNullOrEmpty(filePath) || !new File(filePath).exists() ||
            imageUri.toString().startsWith("content://com.google.android.gallery3d")) {
        filePath = imageUri.toString();
    }

    return filePath;
}
 
Example #24
Source File: Storage.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
private static void setImageSize(ContentValues values, int width, int height)
{
    // The two fields are available since ICS but got published in JB
    if (ApiHelper.HAS_MEDIA_COLUMNS_WIDTH_AND_HEIGHT)
    {
        values.put(MediaColumns.WIDTH, width);
        values.put(MediaColumns.HEIGHT, height);
    }
}
 
Example #25
Source File: Utils.java    From android-utils with MIT License 5 votes vote down vote up
/**
 * @deprecated {@link MediaUtils#getMediaFileName(Context, Uri)}
 * Gets media file name.
 **/
public static String getMediaFileName(Context ctx, Uri mediaUri) {
    String colName = MediaColumns.DISPLAY_NAME;
    Cursor cur = ctx.getContentResolver().query(mediaUri, new String[]{colName}, null, null, null);
    String dispName = null;

    try {
        if (cur != null && cur.getCount() > 0) {
            while (cur.moveToNext()) {
                dispName = cur.getString(cur.getColumnIndex(colName));

                // for unknown reason, the image size for image was found to
                // be 0
                // Log.v( TAG, "#getMediaFileName byte.size: " + size );

                if (TextUtils.isEmpty(colName)) {
                    Log.w(TAG, "#getMediaFileName The file name is blank or null. Reason: UNKNOWN");
                }

            } // end while
        } else if (cur != null && cur.getCount() == 0) {
            Log.e(TAG, "#getMediaFileName File may not exist");
        } else {
            Log.e(TAG, "#getMediaFileName cur is null");
        }
    } finally {
        if (cur != null && !cur.isClosed()) {
            cur.close();
        }
    }

    return dispName;
}
 
Example #26
Source File: NowPlayingAdapter.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public void remove(int which) {
    int cursorPos = getCursorPosition(which);
    mCursor.moveToPosition(cursorPos);
    long id = mCursor.getLong(mCursor.getColumnIndexOrThrow(BaseColumns._ID));
    String mName = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaColumns.TITLE));
    MusicUtils.removeTrack(id);
    String message = mContext.getString(R.string.track_removed_from_playlist, mName);
    Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
	super.remove(which);
}
 
Example #27
Source File: LocalImage.java    From medialibrary with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static void updateWidthAndHeightProjection() {
    if (ApiHelper.HAS_MEDIA_COLUMNS_WIDTH_AND_HEIGHT) {
        PROJECTION[INDEX_WIDTH] = MediaColumns.WIDTH;
        PROJECTION[INDEX_HEIGHT] = MediaColumns.HEIGHT;
    }
}
 
Example #28
Source File: PlaylistListAdapter.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public void remove(int which) {
    int cursorPos = getCursorPosition(which);
    mCursor.moveToPosition(cursorPos);
    long id = mCursor.getLong(mCursor.getColumnIndexOrThrow(Playlists.Members.AUDIO_ID));
    String mName = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaColumns.TITLE));
    if (mPlaylistId >= 0) {
        Uri uri = Playlists.Members.getContentUri(EXTERNAL, mPlaylistId);
        mContext.getContentResolver().delete(uri, Playlists.Members.AUDIO_ID + "=" + id,
                null);
        String message = mContext.getString(R.string.track_removed_from_playlist, mName);
        Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
    }
	super.remove(which);
}
 
Example #29
Source File: AlbumListAdapter.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public void setupViewData(Cursor mCursor) {
   	mLineOneText = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaColumns.TITLE));    	
   	mLineTwoText = mCursor.getString(mCursor.getColumnIndexOrThrow(AudioColumns.ARTIST));    	
       mImageData = new String[]{ mLineTwoText };        
       mPlayingId = MusicUtils.getCurrentAudioId();
       mCurrentId = mCursor.getLong(mCursor.getColumnIndexOrThrow(BaseColumns._ID));
       mListType = TYPE_ARTIST;
}
 
Example #30
Source File: ArtistListAdapter.java    From mobile-manager-tool with MIT License 5 votes vote down vote up
@Override
public void setupViewData(Cursor mCursor) {
   	mLineOneText = mCursor.getString(mCursor.getColumnIndexOrThrow(MediaColumns.TITLE));    	
   	mLineTwoText = mCursor.getString(mCursor.getColumnIndexOrThrow(AudioColumns.ALBUM));    	
       mImageData = new String[]{ mLineTwoText };        
       mPlayingId = MusicUtils.getCurrentAudioId();
       mCurrentId = mCursor.getLong(mCursor.getColumnIndexOrThrow(BaseColumns._ID));
       mListType = TYPE_ARTIST;
}