当前位置: 首页>>代码示例>>Java>>正文


Java DocumentsContract.getDocumentId方法代码示例

本文整理汇总了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);//根據圖片路徑顯示圖片
}
 
开发者ID:Qinlong275,项目名称:AndroidBookTest,代码行数:25,代码来源:MainActivity.java

示例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;
}
 
开发者ID:lbbniu,项目名称:CCDownload,代码行数:22,代码来源:UploadFragment.java

示例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();
}
 
开发者ID:shawnsky,项目名称:RantApp,代码行数:26,代码来源:SelectPhotoFragment.java

示例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;
}
 
开发者ID:838030195,项目名称:DaiGo,代码行数:26,代码来源:VerificationActivity.java

示例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;
}
 
开发者ID:feup-infolab,项目名称:labtablet,代码行数:25,代码来源:FileMgr.java

示例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);      //根据图片路径显示图片
}
 
开发者ID:android-jian,项目名称:topnews,代码行数:27,代码来源:SettingFragment.java

示例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;
}
 
开发者ID:mkulesh,项目名称:microMathematics,代码行数:29,代码来源:AdapterDocuments.java

示例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);//根据图片路径显示图片
}
 
开发者ID:wangyufei1006,项目名称:CameraAlbumTest,代码行数:22,代码来源:MainActivity.java

示例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;
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:20,代码来源:FileHelper.java

示例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;
}
 
开发者ID:wmgylc,项目名称:The-Three-kingdoms-Generals-Dictionary,代码行数:23,代码来源:InfoActivity.java

示例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);
    }
 
开发者ID:ifadai,项目名称:SuperNote,代码行数:25,代码来源:EditNotePresenter.java

示例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;
}
 
开发者ID:EggUncle,项目名称:XposedNavigationBar,代码行数:30,代码来源:ImageUtil.java

示例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);
}
 
开发者ID:JoeSteven,项目名称:BiBi,代码行数:22,代码来源:AvatarUtils.java

示例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;
    }
}
 
开发者ID:rcketscientist,项目名称:DocumentActivity,代码行数:22,代码来源:UsefulDocumentFile.java

示例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);
}
 
开发者ID:zhangxx0,项目名称:FirstCodeUtil,代码行数:24,代码来源:AtyChoosePic.java


注:本文中的android.provider.DocumentsContract.getDocumentId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。