ulmaxy
ulmaxy

Reputation: 870

Return to browser after opening a deeplink in an android app

I'm trying to find a solution for the following use case. On our website, we have a deeplink, by clicking which customer should be either redirected to our app if it's installed or to another web page in the browser (according to the link). What I'm trying to achieve here is to return back to the browser page after the deeplink is handled by our app.

I can technically try to launch an Intent with the URL of the page, but unfortunately, it does not guarantee that we'd return back to the page where the deeplink was clicked, and also the system might ask us to select an app for opening a URL (if it's not set by default). Another problem here is that the link might be opened in a new tab, which is also not very nice.

Is there any way to achieve this?

Upvotes: 1

Views: 2656

Answers (1)

Dimon
Dimon

Reputation: 71

I had similar task and these steps helped me.

  1. With EXTRA_REFERRER you can get something like this (depend from what browser, your activity was launched):
  • android-app://com.opera.browser
  • android-app://org.mozilla.firefox
  • android-app://com.android.chrome
  1. Then extract package name, com.opera.browser for example, and create intent for it with getLaunchIntentForPackage.

  2. Then add Intent.FLAG_ACTIVITY_REORDER_TO_FRONT flag to just created intent. I'm not sure that this step is necessary.

  3. Then startActivity with created intent.

Upvotes: 1

Related Questions