fix: exposed uri error
This commit is contained in:
@@ -1 +1 @@
|
||||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":423},"path":"commonRelease-4.0.3 Alpha4.apk","properties":{"packageId":"org.autojs.autojs","split":"","minSdkVersion":"17"}}]
|
||||
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":424,"versionName":"4.0.3 Alpha5","enabled":true,"outputFile":"commonRelease-4.0.3 Alpha5.apk","fullName":"commonRelease","baseName":"common-release"},"path":"commonRelease-4.0.3 Alpha5.apk","properties":{}}]
|
||||
@@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.FileProvider;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -93,11 +94,37 @@ public class IntentUtil {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static void viewFile(Context context, String path) {
|
||||
path = "file://" + path;
|
||||
public static void viewFile(Context context, String path, String fileProviderAuthority) {
|
||||
String mimeType = MimeTypes.fromFileOr(path, "*/*");
|
||||
viewFile(context, path, mimeType, fileProviderAuthority);
|
||||
}
|
||||
|
||||
public static void viewFile(Context context, String path, String mimeType, String fileProviderAuthority) {
|
||||
Uri uri;
|
||||
if (fileProviderAuthority == null) {
|
||||
uri = Uri.parse("file://" + path);
|
||||
} else {
|
||||
uri = FileProvider.getUriForFile(context, fileProviderAuthority, new File(path));
|
||||
}
|
||||
context.startActivity(new Intent(Intent.ACTION_VIEW)
|
||||
.setDataAndType(Uri.parse(path), mimeType)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
.setDataAndType(uri, mimeType)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION));
|
||||
}
|
||||
|
||||
public static void editFile(Context context, String path, String fileProviderAuthority) {
|
||||
String mimeType = MimeTypes.fromFileOr(path, "*/*");
|
||||
Uri uri;
|
||||
if (fileProviderAuthority == null) {
|
||||
uri = Uri.parse("file://" + path);
|
||||
} else {
|
||||
uri = FileProvider.getUriForFile(context, fileProviderAuthority, new File(path));
|
||||
}
|
||||
context.startActivity(new Intent(Intent.ACTION_EDIT)
|
||||
.setDataAndType(uri, mimeType)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user