mirror of
https://gitee.com/shuto/cordova-plugin-file-opener2.git
synced 2025-01-31 12:02:49 +08:00
Always use FileProvider
This commit is contained in:
parent
8dd6ca756c
commit
0922f8c16e
@ -102,20 +102,13 @@ public class FileOpener2 extends CordovaPlugin {
|
|||||||
File file = new File(fileName);
|
File file = new File(fileName);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
try {
|
try {
|
||||||
Uri path = Uri.fromFile(file);
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
if((Build.VERSION.SDK_INT >= 23 && !contentType.equals("application/vnd.android.package-archive")) || ((Build.VERSION.SDK_INT == 24 || Build.VERSION.SDK_INT == 25) && contentType.equals("application/vnd.android.package-archive"))) {
|
|
||||||
|
|
||||||
Context context = cordova.getActivity().getApplicationContext();
|
Context context = cordova.getActivity().getApplicationContext();
|
||||||
path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file);
|
Uri path = FileProvider.getUriForFile(context, cordova.getActivity().getPackageName() + ".opener.provider", file);
|
||||||
intent.setDataAndType(path, contentType);
|
intent.setDataAndType(path, contentType);
|
||||||
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY);
|
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY);
|
||||||
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
intent.setDataAndType(path, contentType);
|
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
}
|
|
||||||
/*
|
/*
|
||||||
* @see
|
* @see
|
||||||
* http://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin
|
* http://stackoverflow.com/questions/14321376/open-an-activity-from-a-cordovaplugin
|
||||||
|
Loading…
Reference in New Issue
Block a user