From 26b91b49ddee96800d1151848cf9bf4075a34657 Mon Sep 17 00:00:00 2001 From: natsuki tanaka Date: Fri, 1 Mar 2019 14:44:02 +0900 Subject: [PATCH] =?UTF-8?q?Android7.0=E4=BB=A5=E9=99=8D=E3=81=A7PDF?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E3=81=AB=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 +++--- plugin.xml | 23 +++++++++++++++++++---- src/android/MyFileProvider.java | 17 +++++++++++++++++ src/android/WebIntent.java | 26 ++++++++++++++++++++++++-- src/android/res/xml/provider_paths.xml | 15 +++++++++++++++ 5 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 src/android/MyFileProvider.java create mode 100644 src/android/res/xml/provider_paths.xml diff --git a/package.json b/package.json index 06b60dc..fa564af 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "monaca-plugin-webintent", - "version": "1.0.0", - "description": "This plugin allows starting another application on the device", + "name": "monaca-plugin-webintent_Lassic", + "version": "1.0.1", + "description": "Lassic Custom", "author": "Monaca Team", "license": "COPYRIGHT ASIAL CORPORATION", "publishConfig": { diff --git a/plugin.xml b/plugin.xml index 468e78a..db56e12 100755 --- a/plugin.xml +++ b/plugin.xml @@ -1,12 +1,12 @@ + id="monaca-plugin-webintent_Lassic" + version="1.0.1"> WebIntent - This plugin allows starting another application on the device + Lassic Custom @@ -24,8 +24,23 @@ - + + + + + + + + + + diff --git a/src/android/MyFileProvider.java b/src/android/MyFileProvider.java new file mode 100644 index 0000000..c104398 --- /dev/null +++ b/src/android/MyFileProvider.java @@ -0,0 +1,17 @@ +package mobi.monaca.framework.plugin; + +import android.support.v4.content.FileProvider; + +/** + * WebIntent is a PhoneGap plugin that bridges Android intents and web + * applications: + * + * 1. web apps can spawn intents that call native Android applications. 2. + * (after setting up correct intent filters for PhoneGap applications), Android + * intents can be handled by PhoneGap web applications. + * + * @author boris@borismus.com + * + */ +public class MyFileProvider extends FileProvider { +} \ No newline at end of file diff --git a/src/android/WebIntent.java b/src/android/WebIntent.java index ba50f75..b8b630c 100644 --- a/src/android/WebIntent.java +++ b/src/android/WebIntent.java @@ -2,6 +2,7 @@ import java.util.HashMap; import java.util.Map; +import java.io.File; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; @@ -15,6 +16,11 @@ import android.content.Intent; import android.net.Uri; import android.text.Html; +import android.util.Log; + +import mobi.monaca.framework.plugin.MyFileProvider; + +// import android.support.v4.content.FileProvider; /** * WebIntent is a PhoneGap plugin that bridges Android intents and web @@ -253,16 +259,31 @@ public void onNewIntent(Intent intent) { } void startActivity(String action, Uri uri, String type, Map extras) { + + // For Android 7.0 + // add FileProvider + if (type.equals("application/pdf")) { + MyFileProvider myFileProvider = new MyFileProvider(); + File file = new File(uri.toString().replace("content://", "")); + // Log.e("FileProvider", "extras:" + extras + " URI:" + uri.toString() +" file.exists:" + file.exists()); + uri = myFileProvider.getUriForFile(this.cordova.getActivity().getApplicationContext(), + this.cordova.getActivity().getApplicationContext().getPackageName(), file); + } + Intent i = (uri != null ? new Intent(action, uri) : new Intent(action)); - + if (type != null && uri != null) { i.setDataAndType(uri, type); //Fix the crash problem with android 2.3.6 + + if (type.equals("application/pdf")) { + i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // For Android 7.0 + } } else { if (type != null) { i.setType(type); } } - + for (String key : extras.keySet()) { String value = extras.get(key); // If type is text html, the extra text must sent as HTML @@ -292,4 +313,5 @@ void sendBroadcast(String action, Map extras) { this.cordova.getActivity().sendBroadcast(intent); } + } \ No newline at end of file diff --git a/src/android/res/xml/provider_paths.xml b/src/android/res/xml/provider_paths.xml new file mode 100644 index 0000000..5bddeae --- /dev/null +++ b/src/android/res/xml/provider_paths.xml @@ -0,0 +1,15 @@ + + + + + + +