本文整理匯總了Java中android.provider.MediaStore.MediaColumns類的典型用法代碼示例。如果您正苦於以下問題:Java MediaColumns類的具體用法?Java MediaColumns怎麽用?Java MediaColumns使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MediaColumns類屬於android.provider.MediaStore包,在下文中一共展示了MediaColumns類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDataColumn
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
private String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
Cursor cursor = null;
String[] column = {MediaColumns.DATA};
try {
cursor = context.getContentResolver().query(uri, column, selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
final int index = cursor.getColumnIndexOrThrow(column[0]);
return cursor.getString(index);
}
} catch (Exception e) {
Log.e("getRealPath error ", "exception: " + e);
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
示例2: move
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
public boolean move(File srcFile, File targetFile) {
boolean res = srcFile.renameTo(targetFile);
if (res) {
// Add the new file to the medialib
scanFile(targetFile);
// Remove the source file from the medialib
// scanFile(srcFile);
ContentResolver cr = context.getContentResolver();
Uri uri = MediaStore.Files.getContentUri("external");
String where = MediaColumns.DATA + "=?";
String[] selectionArgs = { srcFile.getPath() };
cr.delete(uri, where, selectionArgs);
}
return res;
}
示例3: getUriImagePathQuery
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
/**
* 獲取媒體數據庫路徑 . <br>
* @author liulongzhenhai 2012-8-1 下午5:09:27 <br>
* @param ct 上下文
* @param contentUri URI地址
* @return 返回相應的絕對路徑
*/
public static String getUriImagePathQuery(final Context ct, final Uri contentUri) {
// can post image
if (contentUri == null) {
return "";
}
final String[] proj = { MediaColumns.DATA };
String path = "";
final Cursor cursor = ct.getContentResolver().query(contentUri, proj, null, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
path = cursor.getString(cursor.getColumnIndexOrThrow(MediaColumns.DATA));
}
cursor.close();
}
return path;
}
示例4: getSongListForGenre
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
/**
* @param context The {@link Context} to use.
* @param id The ID of the genre.
* @return The song list for an genre.
*/
public static final long[] getSongListForGenre(final Context context, final long id) {
final String[] projection = new String[]{
BaseColumns._ID
};
String selection = (AudioColumns.IS_MUSIC + "=1") +
" AND " + MediaColumns.TITLE + "!=''";
final Uri uri = MediaStore.Audio.Genres.Members.getContentUri("external", Long.valueOf(id));
Cursor cursor = context.getContentResolver().query(uri, projection, selection,
null, null);
if (cursor != null) {
final long[] mList = getSongListForCursor(cursor);
cursor.close();
cursor = null;
return mList;
}
return sEmptyList;
}
示例5: getImagePath
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
/**
* 獲取圖片路徑 2014年8月12日
*
* @param uri
* @return E-mail:[email protected]
*/
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().replace("file://", "");
}
示例6: getMp3List
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
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;
}
示例7: getSongListForGenre
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
/**
* @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;
}
示例8: doSearch
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
/**
* 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));
}
示例9: onCreateContextMenu
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
@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);
}
}
示例10: onCreateLoader
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
@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);
}
示例11: reloadQueueCursor
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
/**
* 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);
}
示例12: setupFragmentData
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
@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;
}
示例13: setupFragmentData
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
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;
}
示例14: onLoadFinished
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
@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);
}
示例15: setupFragmentData
import android.provider.MediaStore.MediaColumns; //導入依賴的package包/類
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;
}