Android从Google云端硬盘获取Uri路径

我有这个代码文件上传到我的应用程序,当用文件管理器,dropBox或其他任何东西打开文件时,返回的路径是正确的,我可以访问它,我只是遇到谷歌驱动器的问题,它返回一些以“exposed_content”开头的路径,我不能以任何方式“解码”它,我搜索过并没有找到办法,任何人都有任何想法?
if (resultCode == Activity.RESULT_OK) {
            if ((data != null) && (data.getData() != null)) {
                final Uri filePath;
                if (data.getDataString().startsWith("content")) {
                    filePath = getRealPathFromURI(getApplicationContext(),data.getData());
                } else {
                    filePath = data.getData();
                }
                // Todo bug with google drive
                if (filePath.getLastPathSegment() != null) {
                    tvSelectedFile.setText("File selected: " + filePath.getLastPathSegment());

                } else {
                    tvSelectedFile.setText("File can not be accessed,please try another way");
                }

            }
}

解决方法

使用附加的代码…从onActivity结果你将得到内容uri …将此uri传递给给定的方法
public static String getGDriveDataColumn(Context context,Uri uri,String selection,String[] selectionArgs) {
    Cursor cursor = null;
    final String column = "_display_name";
    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;    

}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...