Webview redirects back after open app again - android

I have webview in my android app. The first page on webview is login, where the user inputs an email. After that app redirects to the page to input code in webview.
When a user receives the code, he opens Gmail app (for example), copies the code and when he turns back to my app, webview automatically returns him to the previous page to input the email.
Maybe somebody knows how to fix it?

Related

Android Deep linking is intermittent

We have an Andriod app from where we are starting a brower experiance and loading a page.
On the browser page their are two buttons "Agree" and "Cancel". We have a deep link URL which is being called on click of both buttons and take user back to the app from where the journey started.
Only difference in the functionality is on click of "Agree" we are doing backed calls and after we get response which is taking around 10-15 seconds we are just redirecting chrome to deep link url.
"Cancel" is working seem-less, but on click of "Agree" button browser is not able to understand deep-link url and doing the redirect in same browser session.
This is how we are redirecting chrome to deep-link url.
window.location.replace(redirectUrl);
Here is the conclusion from our debugging. We found out that there is nothing missing in the code.
Chrome doesn’t launch an external app for a given Intent URI in the following cases.
When the Intent URI is redirected from a typed in URL.
When the Intent URI is initiated without user gesture.
On click of Cancel button it is working all the time as there is no backend call.
On Agree button we are calling backend and on completion of a promise we are redirecting back to App. In that scenario chrome is not treating this as a user gesture all the time so failing intermittently.
One way to solve this issue is instead of opening a new browser window open experience in Android WebView.

Chrome custom tab gets sometimes stuck at blank screen during login

We recently integrated AppAuth into our application to automate the OAuth2 authorization code flow. When user wants to login, he is first redirected to our auth server, where he proceeds with the login, and then gets redirected back to the application.
We use chrome-custom-tabs to for opening the login page (AppAuth). The problem is that it sometimes gets stuck at a blank screen (chrome tab displays just blank page without the rendered site or redirect). This happens when the user already has a session in the browser so the tab should close automatically and redirect user back to the application (authenticated). It does not behave consistently and we only experience this issue sometimes (~50/50).
I am happy to add some code but don't know where to start (trying to avoid wall of text). Is there a known issue or caveat?
We tried switching contexts as described here but kept experiencing the same issue.
Lead maintainer of AppAuth here. This is most likely happening because the authorization redirect is happening without any user interaction. Chrome enforces a policy that it will only send redirects to your app if the redirect was triggered by a user action, such as submitting a form that redirects or clicking on a link.
If the IDP you are integrating with supports it, you can pass "prompt=consent" as a parameter to force user interaction. Alternatively, you can set up an intermediary page that captures the redirect and displays a "welcome back" message, with a link or button to return to your app.
Another way is to make the user, use the login screen each time.
just add ".setPrompt("login")" to the authRequestBuilder.
so mine will be:
val authRequest = authRequestBuilder
.setPrompt("login")
.build()

How to detect from which app a user returned to your app?

A user presses on a URL in my app and the URL opens in the mobile browser.
Is it possible that I detect in my app when a user returned from the mobile browser to my app?
Many users will simply read the content of URL and press back to return to my app.
Test case:
user clicks on URL
mobile browser opens the URL
user touches BACK button
app detects that user came back to the app from the mobile browser
If I did not explain this well, please let me know.
I would suggest that you launch the URL with startActivityForResult. Then, when the user returns to your application onActivityResult will be called, and if the RequestCodes align you know it is the web browser.
For more information, take a look at this:
http://developer.android.com/reference/android/app/Activity.html#StartingActivities

How do I remove the browser from the activity stack if it launches my Activity?

We have been working on ways to launch our application from links in Email messages, and we have something that works pretty well. Only URLs with http/https schemes work properly, so we have written a small 'redirector' in our server application that sees we are coming from an Android browser and redirects to a URI with a scheme that our application launches. All of this is working pretty well.
The only bad part is because the browser is launched between clicking the link in the email, and the Application popping up due to the redirect, when the user hits the back button to go back to their email program after using our application, the browser is shown to the user. The browser is left on a blank page, and the user could become confused by this and not know to press the back button again to get back to their email.
When our application is launched from the link the browser will handle the URL and the redirect will cause our application to appear as usual. However, is there a way inside my application to tell Android that my application effectively replaces the browser on the back stack, so that if the back button is pressed, the user goes back to the Email program as if the browser didn't pop up in the first place?
Thanks in advance.
You can skip the entire browser in the middle by using an intent filter. You can register a specific schema to listen for and a given url to launch the application. This will launch your application directly and not put a browser in the middle. The YouTube application uses a method similar I'm sure to open the video directly in the YouTube application. This is a question that might point you in a good direction for implementing this.

Force close the web browser

I have a twitter application which uses Sign-in with twitter.
It's 'Settings' screen opens an instance of web browser which goes to twitter, asks the user to authenticate my client application, and comes back to the 'Settings' page after redirection from twitter.
Every other thing with twitter and else works fine, except this:
After the authentication, when the control has come back into the 'Settings' activity, the browser instance remains opened.
This causes hindrance in the UI experience whenever the user navigates away from the 'Settings' activity by back button, after logging in.
Pressing the back button takes the user to the web browser instead of taking her to the activity she was at before coming to 'Settings' activity.
Is there any way to get rid of this?
Can I pass any flag with the intent that opens the browser so that the browser knows that it has to close or has not to be there in the view stack of my application?
or any other solution?
Thanks!
Is there any chance you can use a WebView instead of starting the browser with an Intent? That way, you have full control over it and can close it whenever you want.

Categories

Resources