cordova-plugin-safariviewcontroller icon indicating copy to clipboard operation
cordova-plugin-safariviewcontroller copied to clipboard

"hide" method is not yet implemented for Android

Open binita12345 opened this issue 7 years ago • 11 comments

Hi i am trying to hide my safariViewController using safariViewController.hide(). but it is throwing error: "Invalid action". Help me.

binita12345 avatar Apr 05 '17 06:04 binita12345

Share your code please.

EddyVerbruggen avatar Apr 05 '17 06:04 EddyVerbruggen

Hi Eddy, i am working on ionic2. here is my code

this.safariViewController.isAvailable() .then((available: boolean) => {

if (available) { console.log('safari view test start'); this.safariViewController.show({ url: data.link, hidden: false, animated: false, transition: 'curl', enterReaderModeIfAvailable: true, tintColor: '#ff0000' }) .then((result: any) => { console.log("result*****: "+JSON.stringify(result)); if(result.event === 'opened') { console.log('Opened'); console.log("data"); console.log("data: "+JSON.stringify(data)); setTimeout(function() { console.log('TESTTTT'); this.safariViewController.hide(); }, 5000);

}
else if(result.event === 'loaded'){
console.log('Loaded');

}
else if(result.event === 'closed') console.log('Closed');

}, (error: any) => console.error(error) ); console.log('safari view test');

} else { // use fallback browser, example InAppBrowser }

});

On Wed, Apr 5, 2017 at 12:14 PM, Eddy Verbruggen [email protected] wrote:

Share your code please.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/EddyVerbruggen/cordova-plugin-safariviewcontroller/issues/62#issuecomment-291769410, or mute the thread https://github.com/notifications/unsubscribe-auth/AWmhs5ihVj-B11oqrQqxWzQNtjlVShf3ks5rszhMgaJpZM4MzztL .

binita12345 avatar Apr 05 '17 08:04 binita12345

Could it be the context of this is lost after the timeout? So this.safariViewController.hide will no longer work.

Looks like you're using TS, so perhaps try this instead, as arrow functions keep track of this for you:

setTimeout(() => {
  console.log('TESTTTT');
  this.safariViewController.hide();
}, 5000);

If that works you can donate me some 🍺 on my Paypal :)

EddyVerbruggen avatar Apr 05 '17 11:04 EddyVerbruggen

nope context of "this" ll not be lost throughout my function. same is working fine for me in IOS but it throws error in android.

On Wed, Apr 5, 2017 at 5:24 PM, Eddy Verbruggen [email protected] wrote:

Could it be the context of this is lost after the timeout? So this.safariViewController.hide will no longer work.

Looks like you're using TS, so perhaps try this instead, as arrow functions keep track of this for you:

setTimeout(() => { console.log('TESTTTT'); this.safariViewController.hide(); }, 5000);

If that works you can donate me some 🍺 on my Paypal :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/EddyVerbruggen/cordova-plugin-safariviewcontroller/issues/62#issuecomment-291838148, or mute the thread https://github.com/notifications/unsubscribe-auth/AWmhs9n8oPh3AXRiKeZY7jWUrlWJgbFgks5rs4DcgaJpZM4MzztL .

binita12345 avatar Apr 06 '17 04:04 binita12345

You're right, hide wasn't implemented on Android. I didn't provide the Android implementation so I don't know why not. Perhaps it's not possible even.

Turning this into a feature request.

EddyVerbruggen avatar Apr 06 '17 13:04 EddyVerbruggen

okay thank you Eddy for your response :)

On Thu, Apr 6, 2017 at 6:54 PM, Eddy Verbruggen [email protected] wrote:

You're right, hide wasn't implemented on Android. I didn't provide the Android implementation so I don't know why not. Perhaps it's not possible even.

Turning this into a feature request.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/EddyVerbruggen/cordova-plugin-safariviewcontroller/issues/62#issuecomment-292173299, or mute the thread https://github.com/notifications/unsubscribe-auth/AWmhs_UPihDhCw9YPpaB1KO40JPvRmsgks5rtOeVgaJpZM4MzztL .

binita12345 avatar Apr 07 '17 04:04 binita12345

Hello!

What is the status of this issue? Is it possible that the "hide" method in Android will be implemented in the next release?

Thanks in advance!

Dimigergo avatar May 24 '17 12:05 Dimigergo

You're welcome to give it a shot if you need it. I personally don't, so..

EddyVerbruggen avatar May 24 '17 12:05 EddyVerbruggen

@Dimigergo, @binita12345 did any of you manage to implement this for Android ? If so, please share.

For my purpose (an oauth authentication), applying the changes described in https://stackoverflow.com/questions/42530178/auto-close-chrome-custom-tab#42530510 closes Android's custom tab after redirecting to the app, which is exactly what I needed.

The changes done are:

  1. add the following line to config.xml: <preference name="AndroidLaunchMode" value="singleTop" />

  2. add the following lines at the begining of startCustomTabActivity in plugins/cordova-plugin-safariviewcontroller/src/android/ChromeCustomTabPlugin.java:

intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Refer to https://bugs.chromium.org/p/chromium/issues/detail?id=543542 , https://bugs.chromium.org/p/chromium/issues/detail?id=545446 , and https://stackoverflow.com/questions/42530178/auto-close-chrome-custom-tab for more information.

semiaddict avatar Dec 19 '17 11:12 semiaddict

Actually, applying the first change, by adding the preference to config.xml seems to be enough to automatically close the tab when redirecting to the app.

semiaddict avatar Dec 19 '17 11:12 semiaddict

Is it possible to implement just a dummy action for android so the exception does not occur anymore?

PowerMogli avatar Oct 01 '20 12:10 PowerMogli