Skip to content

Commit

Permalink
inAppBrowser will allow back-to-the-app-redirections using applicatio…
Browse files Browse the repository at this point in the history
…n's custom scheme

scheme can be configured in config.xml using "CustomAppScheme" proererty
  • Loading branch information
osvso committed Mar 26, 2015
1 parent 9901d62 commit c21943f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/android/InAppBrowser.java
Expand Up @@ -57,6 +57,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import org.apache.cordova.LOG;
import org.apache.cordova.PluginManager;
import org.apache.cordova.PluginResult;
import org.apache.cordova.CordovaPreferences;
import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -84,6 +85,11 @@ public class InAppBrowser extends CordovaPlugin {
private static final String CLEAR_SESSION_CACHE = "clearsessioncache";
private static final String HARDWARE_BACK_BUTTON = "hardwareback";

/*
Configuration property. Custom applicaiton scheme to be handeld in a _system.
*/
private static final String CUSTOM_APPLICATION_SCHEME = "CustomAppScheme";

private InAppBrowserDialog dialog;
private WebView inAppWebView;
private EditText edittext;
Expand Down Expand Up @@ -113,7 +119,7 @@ public boolean execute(String action, CordovaArgs args, final CallbackContext ca
}
final String target = t;
final HashMap<String, Boolean> features = parseFeature(args.optString(2));

Log.d(LOG_TAG, "target = " + target);

this.cordova.getActivity().runOnUiThread(new Runnable() {
Expand Down Expand Up @@ -772,6 +778,7 @@ public InAppBrowserClient(CordovaWebView webView, EditText mEditText) {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
final CordovaPreferences preferences = Config.getPreferences();
String newloc = "";
if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) {
newloc = url;
Expand Down Expand Up @@ -827,6 +834,18 @@ else if (url.startsWith("sms:")) {
LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString());
}
}
else if (url.startsWith(preferences.getString(CUSTOM_APPLICATION_SCHEME, "!@#$"))) {
try {
final Intent intent = new Intent(Intent.ACTION_VIEW);
final Uri uri = Uri.parse(url);
intent.setData(uri);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
cordova.getActivity().startActivity(intent);
} catch (final android.content.ActivityNotFoundException e) {
LOG.e(LOG_TAG, "Error during redirection " + url + ":" + e.toString());
}
newloc = "";
}
else {
newloc = "http://" + url;
}
Expand Down

0 comments on commit c21943f

Please sign in to comment.