From 21b9e36ccb556dd9c8a181943edd66a3c44fc3cf Mon Sep 17 00:00:00 2001 From: liuwenzheng <329541594@qq.com> Date: Thu, 17 Oct 2019 15:17:23 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9download=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +-- .../java/com/moko/beacon/utils/FileUtils.java | 30 +++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index bb87658..6624e18 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "com.moko.beacon" minSdkVersion 18 targetSdkVersion 28 - versionCode 7 - versionName "1.3.1" + versionCode 8 + versionName "1.3.2" javaCompileOptions { annotationProcessorOptions { diff --git a/app/src/main/java/com/moko/beacon/utils/FileUtils.java b/app/src/main/java/com/moko/beacon/utils/FileUtils.java index a511731..9db9066 100644 --- a/app/src/main/java/com/moko/beacon/utils/FileUtils.java +++ b/app/src/main/java/com/moko/beacon/utils/FileUtils.java @@ -39,9 +39,15 @@ public static String getPath(final Context context, final Uri uri) { else if (isDownloadsDocument(uri)) { final String id = DocumentsContract.getDocumentId(uri); - final Uri contentUri = ContentUris.withAppendedId( - Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); - + if (id.startsWith("raw:")) { + final String path = id.replaceFirst("raw:", ""); + return path; + } + Uri contentUri = uri; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { + contentUri = ContentUris.withAppendedId( + Uri.parse("content://downloads/public_downloads"), Long.valueOf(id)); + } return getDataColumn(context, contentUri, null, null); } // MediaProvider @@ -67,6 +73,13 @@ else if (isMediaDocument(uri)) { } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { + //判断QQ文件管理器 + if (isQQMediaDocument(uri)) { + String path = uri.getPath(); + File fileDir = Environment.getExternalStorageDirectory(); + File file = new File(fileDir, path.substring("/QQBrowser".length(), path.length())); + return file.exists() ? file.toString() : null; + } return getDataColumn(context, uri, null, null); } // File @@ -165,4 +178,15 @@ public static byte[] readFile(String filePath) throws Exception { // throw e; // } // } + + /** + * 使用第三方qq文件管理器打开 + * + * @param uri + * + * @return + */ + public static boolean isQQMediaDocument(Uri uri) { + return "com.tencent.mtt.fileprovider".equals(uri.getAuthority()); + } } \ No newline at end of file