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

save lastIntentString in java and get it from javascript with getLastIntent() #126

Merged
merged 3 commits into from
Nov 10, 2015
Merged
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
11 changes: 11 additions & 0 deletions src/android/nl/xservices/plugins/LaunchMyApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class LaunchMyApp extends CordovaPlugin {

private static final String ACTION_CHECKINTENT = "checkIntent";
private static final String ACTION_CLEARINTENT = "clearIntent";
private static final String ACTION_GETLASTINTENT = "getLastIntent";

private String lastIntentString = null;

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
Expand All @@ -28,11 +31,19 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
final Intent intent = ((CordovaActivity) this.webView.getContext()).getIntent();
final String intentString = intent.getDataString();
if (intentString != null && intent.getScheme() != null) {
lastIntentString = intentString;
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, intent.getDataString()));
} else {
callbackContext.error("App was not started via the launchmyapp URL scheme. Ignoring this errorcallback is the best approach.");
}
return true;
} else if (ACTION_GETLASTINTENT.equalsIgnoreCase(action)) {
if(lastIntentString != null) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, lastIntentString));
} else {
callbackContext.error("No intent received so far.");
}
return true;
} else {
callbackContext.error("This plugin only responds to the " + ACTION_CHECKINTENT + " action.");
return false;
Expand Down
14 changes: 14 additions & 0 deletions www/android/LaunchMyApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,18 @@
}

document.addEventListener("deviceready", triggerOpenURL, false);

var launchmyapp = {
getLastIntent: function(success, failure) {
cordova.exec(
success,
failure,
"LaunchMyApp",
"getLastIntent",
[]);
}
}

module.exports = launchmyapp;

}());