本文整理汇总了Java中android.provider.MediaStore.MediaColumns.DATA属性的典型用法代码示例。如果您正苦于以下问题:Java MediaColumns.DATA属性的具体用法?Java MediaColumns.DATA怎么用?Java MediaColumns.DATA使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.provider.MediaStore.MediaColumns
的用法示例。
在下文中一共展示了MediaColumns.DATA属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDataColumn
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
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
/**
* 获取媒体数据库路径 . <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: getImagePath
/**
* 获取图片路径 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://", "");
}
示例5: getDataColumn
public 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 index = cursor.getColumnIndexOrThrow(column);
return cursor.getString(index);
}
} finally {
if (cursor != null)
cursor.close();
}
return null;
}
示例6: getImagePath
/**
* 获取图片路径 2014年8月12日
*
* @param uri
* @param context
* @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();
}
示例7: deleteFile
public synchronized static boolean deleteFile(Context context, String path) {
File file = new File(path);
boolean issucc = false;
if (file.exists()) {
issucc = file.delete();
if (issucc) {
String where = MediaColumns.DATA + "=?";
String[] selectionArgs = new String[] { path };
int columnsNum = context.getContentResolver()
.delete(Images.Media.EXTERNAL_CONTENT_URI, where,
selectionArgs);
if (columnsNum > 0) {
return issucc;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
示例8: getImagePath
/**
* 获取图片路径 2014年8月12日
*
* @param uri
* @param cursor
* @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();
}
示例9: getDataColumn
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;
}
示例10: onActivityResult
/** Resolves the path of the image that was picked. */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaColumns.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
picturePath2 = picturePath;
new LongOperation().execute("");
}
}
示例11: onActivityResult
/** Receives the path of the uploaded image and starts the background thread for Validation**/
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// initializeOpenCVDependencies();
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaColumns.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
picturePath = cursor.getString(columnIndex);
cursor.close();
picturePath2 = picturePath;
new LongOperation().execute("");
}
}
示例12: getImagePath
/**
* 获取图片路径 2014年8月12日
*
* @param uri
* @param cursor
* @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();
}
示例13: getRealPathFromURI
public static String getRealPathFromURI(Activity context, Uri contentUri) {
if (context != null && contentUri != null) {
String[] proj = { MediaColumns.DATA };
Cursor cursor = context.getContentResolver().query(contentUri,
proj, null, null, null);
int s = contentUri.getPath().indexOf("http");
if (s > -1) {
return contentUri.getPath().substring(s,
contentUri.getPath().length());
} else if (cursor != null) {
cursor.moveToFirst();
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
return cursor.getString(column_index);
} else {
// Utils.debug("AiOut","cursor null",3);
return contentUri.toString().replace("file://", "");
}
} else {
return "";
}
}
示例14: getFileUriFromContentUri
/**
* Given an Uri that is a content Uri (e.g.
* content://media/external/images/media/1884) this function returns the
* respective file Uri, that is e.g. file://media/external/DCIM/abc.jpg
*
* @param cameraPicUri
* @return Uri
*/
private Uri getFileUriFromContentUri(Uri cameraPicUri) {
try {
if (cameraPicUri != null
&& cameraPicUri.toString().startsWith("content")) {
String[] proj = { MediaColumns.DATA };
Cursor cursor = getContentResolver().query(cameraPicUri, proj, null, null, null);
cursor.moveToFirst();
// This will actually give you the file path location of the image.
String largeImagePath = cursor.getString(cursor
.getColumnIndexOrThrow(MediaColumns.DATA));
return Uri.fromFile(new File(largeImagePath));
}
return cameraPicUri;
} catch (Exception e) {
return cameraPicUri;
}
}
示例15: fileToContentUri
/**
* Method that converts a file reference to a content uri reference
*
* @param cr A content resolver
* @param path The path to search
* @param volume The volume
* @return Uri The content uri or null if file not exists in the media database
*/
private static Uri fileToContentUri(ContentResolver cr, String path, String volume) {
final String[] projection = {BaseColumns._ID, MediaStore.Files.FileColumns.MEDIA_TYPE};
final String where = MediaColumns.DATA + " = ?";
Uri baseUri = MediaStore.Files.getContentUri(volume);
Cursor c = cr.query(baseUri, projection, where, new String[]{path}, null);
try {
if (c != null && c.moveToNext()) {
int type = c.getInt(c.getColumnIndexOrThrow(
MediaStore.Files.FileColumns.MEDIA_TYPE));
if (type != 0) {
// Do not force to use content uri for no media files
long id = c.getLong(c.getColumnIndexOrThrow(BaseColumns._ID));
return Uri.withAppendedPath(baseUri, String.valueOf(id));
}
}
} finally {
IOUtils.closeQuietly(c);
}
return null;
}