本文整理汇总了Java中android.provider.DocumentsContract.getDocumentId方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentsContract.getDocumentId方法的具体用法?Java DocumentsContract.getDocumentId怎么用?Java DocumentsContract.getDocumentId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.provider.DocumentsContract
的用法示例。
在下文中一共展示了DocumentsContract.getDocumentId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleImageOnKitkat
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@TargetApi(19)
private void handleImageOnKitkat(Intent data){
String imagePath=null;
Uri uri=data.getData();
if (DocumentsContract.isDocumentUri(this,uri)){
//如果是document類型的Uri。則通過document id 處理
String docId=DocumentsContract.getDocumentId(uri);
if ("com.android.providers.media.documents".equals(uri.getAuthority())){
String id=docId.split(":")[1];//解析出文字格式的id
String selection=MediaStore.Images.Media._ID+"="+id;
imagePath=getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,selection);
} else if("com.android.providers.downloads.documents".equals(uri.getAuthority())){
Uri contentUri= ContentUris.withAppendedId(Uri.parse("content://downloads/public" +
"_downloads"),Long.valueOf(docId));
}
}else if ("content".equalsIgnoreCase(uri.getScheme())){
//如果是content類型的Uri,則是用普通方式處理
imagePath=getImagePath(uri,null);
}else if ("file".equalsIgnoreCase(uri.getScheme())){
//如果是file類型的Uri,直接獲取圖片路徑即可
imagePath=uri.getPath();
}
displayImage(imagePath);//根據圖片路徑顯示圖片
}
示例2: getRealPath
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@SuppressLint("NewApi")
private String getRealPath(Uri uri){
String filePath = null;
String uriString = uri.toString();
if(uriString.startsWith("content://media")){
filePath = getDataColumn(context, uri, null, null);
} else if (uriString.startsWith("file")){
filePath = uri.getPath();
} else if (uriString.startsWith("content://com")){
String docId = DocumentsContract.getDocumentId(uri);
String[] split = docId.split(":");
Uri contentUri = null;
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String selection = "_id=?";
String[] selectionArgs = new String[] {split[1]};
filePath = getDataColumn(context, contentUri, selection, selectionArgs);
}
return filePath;
}
示例3: handleImage
import android.provider.DocumentsContract; //导入方法依赖的package包/类
private void handleImage(Uri uri){
String imagePath = null;
if(DocumentsContract.isDocumentUri(getActivity(), uri)){
String docId = DocumentsContract.getDocumentId(uri);
if("com.android.providers.media.documents".equals(uri.getAuthority())){
String id = docId.split(":")[1];
String selection = MediaStore.Images.Media._ID+"="+id;
imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
}
else if("com.android.providers.downloads.documents".equals(uri.getAuthority())){
Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId));
imagePath = getImagePath(contentUri, null);
}
}
else if("content".equalsIgnoreCase(uri.getScheme())){
imagePath = getImagePath(uri, null);
}
else if("file".equalsIgnoreCase(uri.getScheme())){
imagePath = uri.getPath();
}
filePath = imagePath;
Log.i(TAG, "handleImage: Album filepath"+filePath);
getQiniuUpToken();
}
示例4: handleImageOnKitKat
import android.provider.DocumentsContract; //导入方法依赖的package包/类
/**
* 执行打开相册逻辑
*/
@TargetApi(19)
private String handleImageOnKitKat(Intent data) {
String imagePath = null;
Uri uri = data.getData();
if (DocumentsContract.isDocumentUri(this, uri)) {
String docId = DocumentsContract.getDocumentId(uri);
if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
String id = docId.split(":")[1];
String selection = MediaStore.Images.Media._ID + "=" + id;
imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
} else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
Long.valueOf(docId));
imagePath = getImagePath(contentUri, null);
}
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
imagePath = getImagePath(uri, null);
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
imagePath = uri.getPath();
}
return imagePath;
}
示例5: getRealPathFromURI_API19
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@SuppressLint("NewApi")
public static String getRealPathFromURI_API19(Context context, Uri uri){
String filePath = "";
String wholeID = DocumentsContract.getDocumentId(uri);
// Split at colon, use second item in the array
String id = wholeID.split(":")[1];
String[] column = { MediaStore.Images.Media.DATA };
// where id is equal to
String sel = MediaStore.Images.Media._ID + "=?";
Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
column, sel, new String[]{ id }, null);
int columnIndex = cursor.getColumnIndex(column[0]);
if (cursor.moveToFirst()) {
filePath = cursor.getString(columnIndex);
}
cursor.close();
return filePath;
}
示例6: handleImageOnKitKat
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@TargetApi(19)
private void handleImageOnKitKat(Intent data){
String imagePath=null;
Uri uri=data.getData();
if (DocumentsContract.isDocumentUri(getActivity(),uri)){
//如果是 document 类型的 Uri,则通过document id处理
String docId=DocumentsContract.getDocumentId(uri);
if ("com.android.providers.media.documents".equals(uri.getAuthority())){
String id=docId.split(":")[1]; //解析出数字格式的id
String selection=MediaStore.Images.Media._ID+"="+id;
imagePath=getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,selection);
}else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())){
Uri contentUri= ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
Long.valueOf(docId));
imagePath=getImagePath(contentUri,null);
}
}else if ("content".equalsIgnoreCase(uri.getScheme())){
//如果是content类型的Uri 则使用普通方式处理
imagePath=getImagePath(uri,null);
}else if ("file".equalsIgnoreCase(uri.getScheme())){
//如果是file类型的Uri,直接获取图片路径即可
imagePath=uri.getPath();
}
displayImage(imagePath); //根据图片路径显示图片
}
示例7: getDirItemsNumber
import android.provider.DocumentsContract; //导入方法依赖的package包/类
private static int getDirItemsNumber(Context ctx, Uri u)
{
int itemsNumber = 0;
Cursor c = null;
try
{
ContentResolver cr = ctx.getContentResolver();
String dirId = DocumentsContract.getDocumentId(u);
Uri dirUri = DocumentsContract.buildChildDocumentsUriUsingTree(u, dirId);
c = cr.query(dirUri, projection, null, null, null);
if (c != null)
{
itemsNumber = c.getCount();
}
}
catch (Exception e)
{
// notning to do;
}
finally
{
if (c != null)
{
c.close();
}
}
return itemsNumber;
}
示例8: handleImageOnKitKat
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@TargetApi(19)
private void handleImageOnKitKat(Intent data){
String imagePath = null;
Uri uri = data.getData();
if(DocumentsContract.isDocumentUri(this,uri)){
String docId = DocumentsContract.getDocumentId(uri);
if("com.android.provider.media,documents".equals(uri.getAuthority())){
String id = docId.split(":")[1];
String selection = MediaStore.Images.Media._ID + "=" + id;
imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,selection);
}else if("com.android.provider.downloads.documents".equals(uri.getAuthority())){
Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),Long.valueOf(docId));
imagePath = getImagePath(contentUri,null);
}
}else if("content".equalsIgnoreCase(uri.getScheme())){
imagePath = getImagePath(uri,null);
}else if("file".equalsIgnoreCase(uri.getScheme())){
imagePath = uri.getPath();
}
displayImage(imagePath);//根据图片路径显示图片
}
示例9: getPath
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@Nullable public static String getPath(@NonNull Context context, @NonNull Uri uri) {
String filePath = null;
try {
String wholeID = DocumentsContract.getDocumentId(uri);
String id = wholeID.split(":")[1];
String[] column = {MediaStore.Images.Media.DATA};
String sel = MediaStore.Images.Media._ID + "=?";
try (Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
column, sel, new String[]{id}, null)) {
if (cursor != null) {
int columnIndex = cursor.getColumnIndex(column[0]);
if (cursor.moveToFirst()) {
filePath = cursor.getString(columnIndex);
}
}
}
} catch (Exception ignored) {}
return filePath;
}
示例10: handleImage
import android.provider.DocumentsContract; //导入方法依赖的package包/类
private String handleImage(Intent data) {
imagePath = null;
Uri uri = data.getData();
if (DocumentsContract.isDocumentUri(this, uri)) {
String docId = DocumentsContract.getDocumentId(uri);
if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
String id = docId.split(":")[1];
String selection = MediaStore.Images.Media._ID + "=" + id;
imagePath = getPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
} else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"),
Long.valueOf(docId));
imagePath = getPath(contentUri, null);
}
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
imagePath = getPath(uri, null);
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
imagePath = uri.getPath();
}
return imagePath;
}
示例11: handleImageOnKitKat
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@TargetApi(19)
private void handleImageOnKitKat(Intent data) {
String imagePath = null;
Uri uri = data.getData();
if (DocumentsContract.isDocumentUri(mView.getActivity(), uri)) {
// 如果是documentlent类型的URI,则通过docment id处理
String docId = DocumentsContract.getDocumentId(uri);
if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
String id = docId.split(":")[1];
String selection = MediaStore.Images.Media._ID + "=" + id;
imagePath = getImagePatch(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
} else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId));
imagePath = getImagePatch(contentUri, null);
}
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
// 如果是content类型的uri的话,则使用普通方式处理
imagePath = getImagePatch(uri, null);
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
// 若果是file类型的uri,则直接获取图片路径
imagePath = uri.getPath();
}
copyFileInOtherThread(imagePath);
}
示例12: handleImageOnKitKat
import android.provider.DocumentsContract; //导入方法依赖的package包/类
/**
* @param data
* @return 图片路径
*/
public static String handleImageOnKitKat(Intent data) {
String imagePath = "";
Log.i(TAG, "handleImageOnKitKat: ");
Uri uri = data.getData();
if (DocumentsContract.isDocumentUri(MyApplication.getContext(), uri)) {
//如果是document类型的uri,则通过document id处理
String docId = DocumentsContract.getDocumentId(uri);
if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
String id = docId.split(":")[1];//解析出数字格式的ID
String selection = MediaStore.Images.Media._ID + "=" + id;
imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
} else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId));
imagePath = getImagePath(contentUri, null);
}
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
//如果是content类型的uri,则使用普通的方式处理
imagePath = getImagePath(uri, null);
} else if ("file".equalsIgnoreCase(uri.getScheme())) {
//如果是file类型的uri,直接获取图片路径即可
imagePath = uri.getPath();
}
return imagePath;
}
示例13: handleImageBeforeKitkat
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
public void handleImageBeforeKitkat(Intent data) {
String imagePath=null;
Uri uri=data.getData();
if(DocumentsContract.isDocumentUri(mActivity, uri)){
String docid=DocumentsContract.getDocumentId(uri);
if("com.android.providers.media.documents".equals(uri.getAuthority())){
String id=docid.split(":")[1];
String selection= MediaStore.Images.Media._ID+"="+id;
imagePath=getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,selection);
}else if("com.android.providers.downloads.documents".equals(uri.getAuthority())){
Uri contentUri= ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(docid));
imagePath=getImagePath(contentUri,null);
}
}else if("content".equalsIgnoreCase(uri.getScheme())){
imagePath=getImagePath(uri,null);
}
//剪裁图片
cropImage(imagePath);
}
示例14: getDocumentId
import android.provider.DocumentsContract; //导入方法依赖的package包/类
public String getDocumentId()
{
try
{
if (DocumentsContract.isDocumentUri(mContext, mUri))
{
return DocumentsContract.getDocumentId(mUri);
} else
{
return DocumentsContract.getTreeDocumentId(mUri);
}
}
catch (IllegalArgumentException e)
{
// This is not a document uri, for now I'll try to handle this gracefully.
// While it may be convenient for a user to be able to use this object for all uri,
// it may be difficult to manage all aspects gracefully.
return null;
}
}
示例15: handleImageOnKitKat
import android.provider.DocumentsContract; //导入方法依赖的package包/类
@TargetApi(19)
private void handleImageOnKitKat(Intent data) {
String imagePath = null;
Uri uri = data.getData();
if (DocumentsContract.isDocumentUri(this,uri)) {
// 如果是document类型的Uri,则通过document id处理
String docId = DocumentsContract.getDocumentId(uri);
if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
String id = docId.split(":")[1]; // 解析出数字格式的ID
String selection = MediaStore.Images.Media._ID+"="+id;
imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,selection);
} else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),Long.valueOf(docId));
imagePath = getImagePath(contentUri,null);
}
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
// 如果不是document类型的Uri,则使用普通方式处理
imagePath = getImagePath(uri,null);
}
// 根据图片路径显示图片
displayImage(imagePath);
}