cordova-plugin-safariviewcontroller
cordova-plugin-safariviewcontroller copied to clipboard
hidden method for android
Dear @EddyVerbruggen,
I've been struggling a while to get Cookies working fine on iOS, but now I am stuck. My code is working fine on iOS and android, but "hidden" is not working for android. It's opening visible. The cookies will be set as wished but as there is not even a .hide() method, everything will break on android.
Is there any chance to get hidden loading working for android too?
Hi! I'm not the one that created the Android portion of this plugin so I'm not the most qualified to dive into those details. Others perhaps?
I've ended up using InAppBrowser on Android, as it has the hidden feature and it is working as expected now. Thanks anyway @EddyVerbruggen
cordova.InAppBrowser.open(imgAdSrcWithMagicCookie, '_blank', 'location=yes,clearsessioncache=no,clearcache=no,hidden=yes');
// and now open the real url
cordova.InAppBrowser.open(anchor, '_blank', 'location=no,clearsessioncache=no,clearcache=no,hidden=no');
It's important to set clearcache and clearsessioncache to "no". Might help anyone
Hello, Same problem as @Hirbod
I need to get chrome cookies because it is chrome that deals with the authentication part. I wanted to use the method "6. Reading Safari Data and Cookies with Cordova" but the hidden world on Android does not work.
I need to recover cookies to give cookies to InAppBrowser because it allows to hide the url bar and listen to the events.
Can not customize safariviewcontroller and listen to url called
A solution?
Thank you
This is what I made changes in plugin at my end and it is working. I followed following link of stackoverflow for how to close CustomChromeTab: https://stackoverflow.com/a/41596629/842607
I made sure that in config.xml I have added line under <platform name="android">
<preference name="AndroidLaunchMode" value="singleTask" />
This will make sure that it will have just single task of that screen, other screen will be overlapped without creating stack of activtivies
Next thing under src/android folder in ChromeCustomTabPlugin.java file, for overriden method execute() hide case is missing. For that I have added following line
case "hide": {
cordova.getActivity().startActivity(new Intent(cordova.getActivity(), cordova.getActivity().getClass()));
return true;
}
Thus that method will look like this:
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
switch (action) {
case "isAvailable":
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, mCustomTabPluginHelper.isAvailable()));
return true;
case "show": {
final JSONObject options = args.getJSONObject(0);
final String url = options.optString("url");
if(TextUtils.isEmpty(url)){
JSONObject result = new JSONObject();
result.put("error", "expected argument 'url' to be non empty string.");
PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, result);
callbackContext.sendPluginResult(pluginResult);
return true;
}
final String toolbarColor = options.optString("toolbarColor");
final Boolean showDefaultShareMenuItem = options.optBoolean("showDefaultShareMenuItem");
String transition = "";
mStartAnimationBundle = null;
final Boolean animated = options.optBoolean("animated", true);
if(animated) transition = options.optString("transition", "slide");
PluginResult pluginResult;
JSONObject result = new JSONObject();
if(isAvailable()) {
try {
this.show(url, getColor(toolbarColor), showDefaultShareMenuItem, transition);
result.put("event", "loaded");
pluginResult = new PluginResult(PluginResult.Status.OK, result);
pluginResult.setKeepCallback(true);
this.callbackContext = callbackContext;
} catch (Exception ex) {
result.put("error", ex.getMessage());
pluginResult = new PluginResult(PluginResult.Status.ERROR, result);
}
} else {
result.put("error", "custom tabs are not available");
pluginResult = new PluginResult(PluginResult.Status.ERROR, result);
}
callbackContext.sendPluginResult(pluginResult);
return true;
}
case "connectToService": {
if (bindCustomTabsService())
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
else
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "Failed to connect to service"));
return true;
}
case "warmUp": {
if (warmUp()) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
} else {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "Failed to warm up service"));
}
return true;
}
case "mayLaunchUrl": {
final String url = args.getString(0);
if(mayLaunchUrl(url)){
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
} else {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR,String.format("Failed prepare to launch url: %s", url)));
}
return true;
}
case "hide": {
cordova.getActivity().startActivity(new Intent(cordova.getActivity(), cordova.getActivity().getClass()));
return true;
}
}
return false;
}
Using this way hide started working even on Android platform.
@jimitpatel do you have a fork with that code somewhere on Github?
@jimitpatel an will your code work with "singleTop" (this is what I've set currently)
@Hirbod , I don't have any fork of this. But was facing this issue and found out solution so in return I have posted it over here. Additionally, I can't push on repository from my office :D :D If I do I will be out of the company.
As of singleTop it's not an issue. I have just added it because we didn't want user to access chrome tab by selecting the app from background. Crux of the code is that hide case in execute method.
So if I get you right, @jimitpatel, this will only give us the ability to close it, but not to start a hidden tab, right?
Next thing under
src/androidfolder inChromeCustomTabPlugin.javafile, for overriden methodexecute()hide case is missing. For that I have added following linecase "hide": { cordova.getActivity().startActivity(new Intent(cordova.getActivity(), cordova.getActivity().getClass())); return true; }Using this way hide started working even on Android platform.
I've tested this code and it works. It would be great having this feature available @EddyVerbruggen :-)
@plvaldes Happy to merge a PR