-1

Hello I have a webview android app. When someone open my app. my website opens inside app as webview application. But I want to open url inside app when someone call my website url in own browser.

E.g. when i call www.fb.com/somepage , facebook opens directly own application inside my phone. I dont visit page over browser I try to do like this. How will I do ?

I searched everyrhing i imagine, i could not find helpful articles about it. I searched supported urls or supported webpages for android. I found a lot of things. They wrote a lot of codes. i dont think i need a lot of codes for catch my website urls. am not i right ?

I have already webview application. if i will do easy way like something change in manifest or my mainactivity file. I want to do like this way.

Thank you for help

  • use chrome custom tabs https://labs.ribot.co.uk/exploring-chrome-customs-tabs-on-android-ef427effe2f4#.p88eugs3l this will help you – Shubham Shukla Feb 05 '17 at 14:46
  • Are your thinking of deep linking? https://developer.android.com/training/app-indexing/deep-linking.html – A.D. Feb 05 '17 at 18:42

1 Answers1

0

What is needed is an intent-filter for your View action that you'd link to a url scheme.

In your Manifest XML file... The View intent represents the action while the BROWSABLE category responds to web URIs.

Defining the scheme

<activity android:name=".MainActivity>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" 
         android:host="your-website.com" 
         android:path="/somepage/" />
    </intent-filter>
</activity> 

However, the user must have your app already installed or else s/he will get an error message in the browser. You would abslutely need a fallback. One way to deal with the error problem is to use some Javascript check to verify if user has the app installed (if you are using a Javascript like AngularJS you can bind it to an onclick. If not you can use a redirect of some kind with Javascript or without). If the app is not installed, the user goes to the regular website url. Else, s/he jumps to app.

Handling redirections for users who do not have the app installed

In your website file or in your template file, use Javascript

<script>
  //any conditional logic 
  if( navigator.userAgent.match(/android/i) ) {
  // redirect to App
  } else {
  // stay/redirect to website or something like getting them to install the app  
  }
</script>

Now when the user clicks on <a href="http://yourweb.com/somepage/">Your Text </a>, s/he gets to the app but if the app is not installed s/he gets to the page on the browser or the Play Store (see notes below).

Other options

There is another way of doing all of the above. Instead of defing an http scheme, you could have your own custom URI.

<intent-filter>
  <data android:scheme="your-custom-URI" />

</intent-filter>

and in your web template file within some sort of conditionals for the redirection fallback...

<a href="your-custom-URI://somepage">Your Text</a>

Extra Notes

  • Something that would need your attention concerns some browser specifics. Here is how Google Chrome treats the subject.

  • If have your app on the Play Store you can refer the user to market://details?id=com.your.app.package to download it.

  • You can achieve more than that with some Javascript library such as AngularJS, Vue, etc in your website.

Community
  • 1
  • 1
Gonzoarte
  • 19
  • 3
  • For more details, refer to [Intents and Intent Filters](https://developer.android.com/guide/components/intents-filters.html) – Gonzoarte Feb 07 '17 at 05:24