本文整理汇总了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);
}