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

Android从Google云端硬盘获取Uri路径,第1张

概述我有这个代码将文件上传到我的应用程序,当用文件管理器,dropbox或其他任何东西打开文件时,返回的路径是正确的,我可以访问它,我只是遇到谷歌驱动器的问题,它返回一些以“exposed_content”开头的路径,我不能以任何方式“解码”它,我搜索过并没有找到办法,任何人都有任何想法? if (resultCode == Activity.RESULT_OK) { if ( 我有这个代码将文件上传到我的应用程序,当用文件管理器,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从Google云端硬盘获取Uri路径全部内容,希望文章能够帮你解决Android从Google云端硬盘获取Uri路径所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1138182.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存