當前位置: 首頁>>代碼示例>>Java>>正文


Java Activity.managedQuery方法代碼示例

本文整理匯總了Java中android.app.Activity.managedQuery方法的典型用法代碼示例。如果您正苦於以下問題:Java Activity.managedQuery方法的具體用法?Java Activity.managedQuery怎麽用?Java Activity.managedQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.app.Activity的用法示例。


在下文中一共展示了Activity.managedQuery方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAbsoluteImagePath

import android.app.Activity; //導入方法依賴的package包/類
/**
 * 通過uri獲取文件的絕對路徑
 *
 * @param uri
 * @return
 */
@SuppressWarnings("deprecation")
public static String getAbsoluteImagePath(Activity context, Uri uri) {
    String imagePath = "";
    String[] proj = {MediaStore.Images.Media.DATA};
    Cursor cursor = context.managedQuery(uri, proj, // Which columns to
            // return
            null, // WHERE clause; which rows to return (all rows)
            null, // WHERE clause selection arguments (none)
            null); // Order-by clause (ascending by name)

    if (cursor != null) {
        int column_index = cursor
                .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        if (cursor.getCount() > 0 && cursor.moveToFirst()) {
            imagePath = cursor.getString(column_index);
        }
    }

    return imagePath;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:27,代碼來源:ImageUtils.java

示例2: loadImgThumbnail

import android.app.Activity; //導入方法依賴的package包/類
/**
 * 獲取圖片縮略圖 隻有Android2.1以上版本支持
 *
 * @param imgName
 * @param kind    MediaStore.Images.Thumbnails.MICRO_KIND
 * @return
 */
@SuppressWarnings("deprecation")
public static Bitmap loadImgThumbnail(Activity context, String imgName,
                                      int kind) {
    Bitmap bitmap = null;

    String[] proj = {MediaStore.Images.Media._ID,
            MediaStore.Images.Media.DISPLAY_NAME};

    Cursor cursor = context.managedQuery(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj,
            MediaStore.Images.Media.DISPLAY_NAME + "='" + imgName + "'",
            null, null);

    if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) {
        ContentResolver crThumb = context.getContentResolver();
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 1;
        bitmap = MethodsCompat.getThumbnail(crThumb, cursor.getInt(0),
                kind, options);
    }
    return bitmap;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:30,代碼來源:ImageUtils.java

示例3: getLatestImage

import android.app.Activity; //導入方法依賴的package包/類
/**
 * 獲取SD卡中最新圖片路徑
 *
 * @return
 */
public static String getLatestImage(Activity context) {
    String latestImage = null;
    String[] items = {MediaStore.Images.Media._ID,
            MediaStore.Images.Media.DATA};
    Cursor cursor = context.managedQuery(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, items, null,
            null, MediaStore.Images.Media._ID + " desc");

    if (cursor != null && cursor.getCount() > 0) {
        cursor.moveToFirst();
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor
                .moveToNext()) {
            latestImage = cursor.getString(1);
            break;
        }
    }

    return latestImage;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:25,代碼來源:ImageUtils.java

示例4: getFilePath

import android.app.Activity; //導入方法依賴的package包/類
public static String getFilePath(Activity activity, Uri uri) {

		String[] proj = { MediaStore.Images.Media.DATA };
		Cursor cursor = activity.managedQuery(uri, proj, null, null, null);
		// 按我個人理解 這個是獲得用戶選擇的圖片的索引值
		int column_index = cursor
				.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);

		// 將光標移至開頭 ,這個很重要,不小心很容易引起越界

		cursor.moveToFirst();
		// 最後根據索引值獲取圖片路徑
		String path = cursor.getString(column_index);
		return path;
	}
 
開發者ID:PlutoArchitecture,項目名稱:Pluto-Android,代碼行數:16,代碼來源:PhotoUtil.java

示例5: getPathFromUri

import android.app.Activity; //導入方法依賴的package包/類
static String getPathFromUri(Intent intent, Activity activity){
    Uri uri = intent.getExtras().getParcelable(Intent.EXTRA_STREAM);
    if (uri.getScheme().equalsIgnoreCase("content")){
        String[] proj = { MediaStore.Images.Media.DATA };
        Cursor cursor = activity.managedQuery(uri, proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        cursor.moveToFirst();
        return cursor.getString(column_index);
    } else return uri.getPath();
}
 
開發者ID:archos-sa,項目名稱:aos-FileCoreLibrary,代碼行數:11,代碼來源:Utils.java

示例6: getPath

import android.app.Activity; //導入方法依賴的package包/類
/**
 * Función que obtiene el path de un bitmap para cargarlo en el imageView.
 *
 * @param uri
 * @param activity
 * @return
 */
public String getPath(Uri uri, Activity activity) {
    String[] projection = {MediaStore.MediaColumns.DATA};
    Cursor cursor = activity
            .managedQuery(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}
 
開發者ID:ur13l,項目名稱:Guanajoven,代碼行數:16,代碼來源:EditarDatosFragment.java

示例7: getRealPathFromUri

import android.app.Activity; //導入方法依賴的package包/類
public static String getRealPathFromUri(Activity activity, Uri uri) {
    Cursor managedQuery = activity.managedQuery(uri, new String[]{"_data"}, null, null, null);
    if (managedQuery == null) {
        return null;
    }
    int columnIndexOrThrow = managedQuery.getColumnIndexOrThrow("_data");
    managedQuery.moveToFirst();
    return managedQuery.getString(columnIndexOrThrow);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:10,代碼來源:SystemUtils.java

示例8: getPath

import android.app.Activity; //導入方法依賴的package包/類
public String getPath(Uri uri, Activity activity) {
    String[] projection = { MediaStore.MediaColumns.DATA };
    Cursor cursor = activity
            .managedQuery(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}
 
開發者ID:nelladragon,項目名稱:scab,代碼行數:9,代碼來源:ChoosePhotoActivity.java


注:本文中的android.app.Activity.managedQuery方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。