Skip to content

Commit

Permalink
选择download文件崩溃
Browse files Browse the repository at this point in the history
  • Loading branch information
liuwenzheng committed Oct 17, 2019
1 parent 7deb320 commit 21b9e36
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 27 additions & 3 deletions app/src/main/java/com/moko/beacon/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 21b9e36

Please sign in to comment.