Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
23 changes: 19 additions & 4 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin
xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="monaca-plugin-webintent"
version="1.0.0">
id="monaca-plugin-webintent_Lassic"
version="1.0.1">

<name>WebIntent</name>
<description>
This plugin allows starting another application on the device
Lassic Custom
</description>
<engines>
<engine name="cordova" version=">=2.9.0" />
Expand All @@ -24,8 +24,23 @@
<param name="android-package" value="mobi.monaca.framework.plugin.WebIntent"/>
</feature>
</config-file>

<source-file src="src/android/WebIntent.java" target-dir="src/mobi/monaca/framework/plugin" />

<!-- For Android 7.0 -->
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<provider
android:name="mobi.monaca.framework.plugin.MyFileProvider"
android:authorities="$PACKAGE_NAME"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
</config-file>
<source-file src="src/android/MyFileProvider.java" target-dir="src/mobi/monaca/framework/plugin"/>
<resource-file src="src/android/res/xml/provider_paths.xml" target="res/xml/provider_paths.xml"/>

</platform>
</plugin>
17 changes: 17 additions & 0 deletions src/android/MyFileProvider.java
Original file line number Diff line number Diff line change
@@ -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 {
}
26 changes: 24 additions & 2 deletions src/android/WebIntent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -253,16 +259,31 @@ public void onNewIntent(Intent intent) {
}

void startActivity(String action, Uri uri, String type, Map<String, String> 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
Expand Down Expand Up @@ -292,4 +313,5 @@ void sendBroadcast(String action, Map<String, String> extras) {

this.cordova.getActivity().sendBroadcast(intent);
}

}
15 changes: 15 additions & 0 deletions src/android/res/xml/provider_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path
name="external_files"
path="." />
<cache-path
name="cache"
path="." />
<external-cache-path
name="external_cache"
path="." />
<files-path
name="files"
path="." />
</paths>