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


Java DocumentsContract类代码示例

本文整理汇总了Java中android.provider.DocumentsContract的典型用法代码示例。如果您正苦于以下问题:Java DocumentsContract类的具体用法?Java DocumentsContract怎么用?Java DocumentsContract使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DocumentsContract类属于android.provider包,在下文中一共展示了DocumentsContract类的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: listFiles

import android.provider.DocumentsContract; //导入依赖的package包/类
public static Uri[] listFiles(Context context, Uri self) {
    final ContentResolver resolver = context.getContentResolver();
    final Uri childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree(self,
            DocumentsContract.getDocumentId(self));
    final ArrayList<Uri> results = new ArrayList<Uri>();

    Cursor c = null;
    try {
        c = resolver.query(childrenUri, new String[] {
                DocumentsContract.Document.COLUMN_DOCUMENT_ID }, null, null, null);
        while (c.moveToNext()) {
            final String documentId = c.getString(0);
            final Uri documentUri = DocumentsContract.buildDocumentUriUsingTree(self,
                    documentId);
            results.add(documentUri);
        }
    } catch (Exception e) {
        Log.w(TAG, "Failed query: " + e);
    } finally {
        closeQuietly(c);
    }

    return results.toArray(new Uri[results.size()]);
}
 
开发者ID:commonsguy,项目名称:cwac-document,代码行数:25,代码来源:DocumentsContractApi21.java

示例3: doMoveFilesAPI21

import android.provider.DocumentsContract; //导入依赖的package包/类
/**
 * Move a file using the new API 21 methods.
 *
 * @param data    File rename data info.
 * @param oldFile Old file reference.
 * @param newFile New file reference.
 * @return True if the file was moved.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private boolean doMoveFilesAPI21(Uri oldUri, FileRenameData data, File oldFile, File newFile) throws FileNotFoundException {
    File newParent = newFile.getParentFile();
    Uri newParentUri = mApplication.getDocumentUri(mSelectedFolders, newParent.getAbsolutePath());
    Uri newUri = DocumentsContract.createDocument(mContentResolver, newParentUri,
            data.getMimeType(), newFile.getName());
    boolean result = false;
    long size = 0;
    try {
        if (oldUri != null && newUri != null) {
            size = copyFileWithStreams(oldUri, newUri);
        }
        result = (size > 0);
    } catch (Exception e) {
        mApplication.logE(TAG, "doMoveFilesNewAPI " + oldFile + " to " + newFile, e);
    }
    if (result) {
        result = DocumentsContract.deleteDocument(mContentResolver, oldUri);
        if (result && newFile.exists()) {
            newFile.setLastModified(data.getDateAdded());
        }
    }
    return result;
}
 
开发者ID:ciubex,项目名称:dscautorename,代码行数:33,代码来源:FileRenameThread.java

示例4: onRun

import android.provider.DocumentsContract; //导入依赖的package包/类
@Override
public void onRun() throws Throwable {
    os = new FileOutputStream(file);
    if (file != null)
        size = file.length();
    Util.log("Delete ", file);
    file.delete();
    FileUtils.forceDelete(file);
    if (uri != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
            DocumentsContract.deleteDocument(context.getContentResolver(), uri); //For kitkat users
        context.getContentResolver().delete(uri, null, null); //Try to delete under content resolver
    }
    new SingleMediaScanner(context, file); //Rescan and remove from gallery
    Storage.shredFile(os, size, file);
    file.delete();
    FileUtils.forceDelete(file);
}
 
开发者ID:SecrecySupportTeam,项目名称:secrecy,代码行数:19,代码来源:DeleteFileJob.java

示例5: 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

示例6: 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

示例7: 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,代码来源:ModifyInfoActivity.java

示例8: handleImageOnKitKat

import android.provider.DocumentsContract; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
public 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/punlic_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())){
        imagePath=uri.getPath();
    }
    displayImage(imagePath);//根据图片路径显示图片
}
 
开发者ID:guzhigang001,项目名称:QNewsDemo,代码行数:25,代码来源:MainActivity.java

示例9: 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

示例10: 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

示例11: canWrite

import android.provider.DocumentsContract; //导入依赖的package包/类
public static boolean canWrite(Context context, Uri self) {
    // Ignore if grant doesn't allow write
    if (context.checkCallingOrSelfUriPermission(self, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
            != PackageManager.PERMISSION_GRANTED) {
        return false;
    }

    final String type = getRawType(context, self);
    final int flags = queryForInt(context, self, DocumentsContract.Document.COLUMN_FLAGS, 0);

    // Ignore documents without MIME
    if (TextUtils.isEmpty(type)) {
        return false;
    }

    // Deletable documents considered writable
    if ((flags & DocumentsContract.Document.FLAG_SUPPORTS_DELETE) != 0) {
        return true;
    }

    if (DocumentsContract.Document.MIME_TYPE_DIR.equals(type)
            && (flags & DocumentsContract.Document.FLAG_DIR_SUPPORTS_CREATE) != 0) {
        // Directories that allow create considered writable
        return true;
    } else if (!TextUtils.isEmpty(type)
            && (flags & DocumentsContract.Document.FLAG_SUPPORTS_WRITE) != 0) {
        // Writable normal files considered writable
        return true;
    }

    return false;
}
 
开发者ID:commonsguy,项目名称:cwac-document,代码行数:33,代码来源:DocumentsContractApi19.java

示例12: getPicturePathFromUriAboveApi19

import android.provider.DocumentsContract; //导入依赖的package包/类
private static String getPicturePathFromUriAboveApi19(Context context, Uri uri) {
    String filePath = null;
    if (DocumentsContract.isDocumentUri(context, uri)) {
        // 如果是document类型的 uri, 则通过document id来进行处理
        String documentId = DocumentsContract.getDocumentId(uri);
        if (isMediaDocument(uri)) { // MediaProvider
            // 使用':'分割
            String id = documentId.split(":")[1];

            String selection = MediaStore.Images.Media._ID + "=?";
            String[] selectionArgs = {id};
            filePath = getDataColumn(context, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection, selectionArgs);
        } else if (isDownloadsDocument(uri)) { // DownloadsProvider
            Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(documentId));
            filePath = getDataColumn(context, contentUri, null, null);
        }
    } else if ("content".equalsIgnoreCase(uri.getScheme())) {
        // 如果是 content 类型的 Uri
        filePath = getDataColumn(context, uri, null, null);
    } else if ("file".equals(uri.getScheme())) {
        // 如果是 file 类型的 Uri,直接获取图片对应的路径
        filePath = uri.getPath();
    }
    return filePath;
}
 
开发者ID:MRYangY,项目名称:YZxing,代码行数:26,代码来源:UriUtils.java

示例13: 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

示例14: 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

示例15: 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


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