本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}