Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update WebIntent.java #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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 README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# WebIntents plugin for Phonegap #
By Boris Smus
By Mahomedalid Pacheco (fork of Boris Smus)

## Adding the Plugin to your project ##
1. To install the plugin, move webintent.js to your project's www folder and include a reference to it in your html files.
2. Create the path "com/borismus/webintent" within your project's src/ folder and move the java file into it.
2. Create the path "com/lizardsc/webintent" within your project's src/ folder and move the java file into it.
3. Add the plugin to your `res/xml/config.xml` file:

`<plugin name="WebIntent" value="com.borismus.webintent.WebIntent" />`
`<plugin name="WebIntent" value="com.lizardsc.webintent.WebIntent" />`

## Using the plugin ##
The plugin creates the object `window.plugins.webintent` with five methods:
Expand Down
6 changes: 3 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:rim="http://www.blackberry.com/ns/widgets"
xmlns:android="http://schemas.android.com/apk/res/android"
id="com.borismus.webintent"
id="com.lizardsc.webintent"
version="0.1.0">
<name>WebIntent</name>
<description>Web Intent Plugin</description>
Expand All @@ -18,11 +18,11 @@
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="WebIntent" >
<param name="android-package" value="com.borismus.webintent"/>
<param name="android-package" value="com.lizardsc.webintent"/>
</feature>
</config-file>

<source-file src="src/android/WebIntent.java" target-dir="src/com/borismus" />
<source-file src="src/android/WebIntent.java" target-dir="src/com/lizardsc" />
</platform>

</plugin>
39 changes: 24 additions & 15 deletions src/android/WebIntent.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.borismus.webintent;
package com.lizardsc.webintent;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -24,7 +24,7 @@
* (after setting up correct intent filters for PhoneGap applications), Android
* intents can be handled by PhoneGap web applications.
*
* @author boris@borismus.com
* @author boris@lizardsc.com
*
*/
public class WebIntent extends Plugin {
Expand All @@ -51,22 +51,31 @@ public PluginResult execute(String action, JSONArray args, String callbackId) {

// Parse the arguments
JSONObject obj = args.getJSONObject(0);
String type = obj.has("type") ? obj.getString("type") : null;
Uri uri = obj.has("url") ? Uri.parse(obj.getString("url")) : null;
JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null;
Map<String, String> extrasMap = new HashMap<String, String>();

if(obj.has("package") {
String package = obj.has("package") ? obj.getString("package");
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("package");
((DroidGap)this.cordova.getActivity()).startActivity(LaunchIntent);

// Populate the extras if any exist
if (extras != null) {
JSONArray extraNames = extras.names();
for (int i = 0; i < extraNames.length(); i++) {
String key = extraNames.getString(i);
String value = extras.getString(key);
extrasMap.put(key, value);
} else {
String type = obj.has("type") ? obj.getString("type") : null;
Uri uri = obj.has("url") ? Uri.parse(obj.getString("url")) : null;
JSONObject extras = obj.has("extras") ? obj.getJSONObject("extras") : null;
Map<String, String> extrasMap = new HashMap<String, String>();

// Populate the extras if any exist
if (extras != null) {
JSONArray extraNames = extras.names();
for (int i = 0; i < extraNames.length(); i++) {
String key = extraNames.getString(i);
String value = extras.getString(key);
extrasMap.put(key, value);
}
}

startActivity(obj.getString("action"), uri, type, extrasMap);
}

startActivity(obj.getString("action"), uri, type, extrasMap);

return new PluginResult(PluginResult.Status.OK);

} else if (action.equals("hasExtra")) {
Expand Down