From 44b95d7b7054b9e2cff31a128572f23b09237c6c Mon Sep 17 00:00:00 2001 From: Joshua <8Joshua@web.de> Date: Tue, 6 Nov 2018 17:39:14 +0100 Subject: [PATCH] =?UTF-8?q?Download=20=C3=BCberarbeitet,=20nun=20wird=20di?= =?UTF-8?q?e=20Datei=20vom=20richtigen=20Standard=20Programm=20ge=C3=B6ffn?= =?UTF-8?q?et?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 9 +++++++ .../fuplanner/services/KVV/Download.java | 26 ++++++++++++++++--- app/src/main/res/xml/provider_paths.xml | 4 +++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 app/src/main/res/xml/provider_paths.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9948868..2115831 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -24,6 +24,15 @@ + + + \ No newline at end of file diff --git a/app/src/main/java/de/sebse/fuplanner/services/KVV/Download.java b/app/src/main/java/de/sebse/fuplanner/services/KVV/Download.java index 8fcfb83..4c03d45 100644 --- a/app/src/main/java/de/sebse/fuplanner/services/KVV/Download.java +++ b/app/src/main/java/de/sebse/fuplanner/services/KVV/Download.java @@ -15,6 +15,7 @@ import java.util.Arrays; import androidx.annotation.Nullable; import androidx.core.app.ActivityCompat; +import androidx.core.content.FileProvider; import de.sebse.fuplanner.MainActivity; import de.sebse.fuplanner.R; import de.sebse.fuplanner.services.KVV.types.Resource; @@ -23,7 +24,10 @@ import de.sebse.fuplanner.tools.RequestPermissionsResultListener; import de.sebse.fuplanner.tools.UtilsDate; import de.sebse.fuplanner.tools.logging.Logger; +import static android.content.Intent.normalizeMimeType; +import static androidx.core.app.ActivityCompat.startActivityForResult; import static androidx.core.content.ContextCompat.checkSelfPermission; +import static androidx.core.content.ContextCompat.startActivity; public class Download { @@ -31,6 +35,7 @@ public class Download { private final ActivityInterface activityInterface; private RequestedDownload requestedDownload; private Logger log = new Logger(this); + static final int REQUEST_IMAGE_OPEN = 1; public Download(ContextInterface contextInterface, ActivityInterface activityInterface) { @@ -55,7 +60,7 @@ public class Download { if (file.getModifiedDate() != 0) { if (!message.isEmpty()) message += "\n"; - resources.getString(R.string.last_modified_on, UtilsDate.getModifiedDateTime(contextInterface.get(), file.getModifiedDate())); + message += resources.getString(R.string.last_modified_on, UtilsDate.getModifiedDateTime(contextInterface.get(), file.getModifiedDate())); } alertDialogBuilder @@ -181,9 +186,17 @@ public class Download { } private void fileOpen(File url){ - Uri uri = Uri.fromFile(url); - Intent intent = new Intent();//Intent.ACTION_VIEW + Uri uri = FileProvider.getUriForFile(contextInterface.get(), contextInterface.get().getApplicationContext().getPackageName() + ".my.provider", url); + + Intent intent; + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { + intent = new Intent(Intent.ACTION_VIEW); + } else { + intent = new Intent(); + } + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); // Check what kind of file you are trying to open, by comparing the url with extensions. // When the if condition is matched, plugin sets the correct intent (mime) type, // so Android knew what application to use to open the file @@ -222,13 +235,18 @@ public class Download { intent.setDataAndType(uri, "video/*"); } else { //if you want you can also define the intent type for any other file - //additionally use else clause below, to manage other unknown extensions //in this case, Android will show all applications installed on the device //so you can choose which application to use intent.setDataAndType(uri, "*/*"); } + //intent.addCategory(Intent.CATEGORY_OPENABLE); + // Only the system receives the ACTION_OPEN_DOCUMENT, so no need to test. + + + + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); contextInterface.get().startActivity(intent); diff --git a/app/src/main/res/xml/provider_paths.xml b/app/src/main/res/xml/provider_paths.xml new file mode 100644 index 0000000..4495c28 --- /dev/null +++ b/app/src/main/res/xml/provider_paths.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file