How to make my webview open links from other apps

0

I have a webview application and I want it to open links from other apps, I already put the intent filter now I need to find the code that makes it open links from other apps. Thanks to whoever respond.

    
asked by anonymous 12.12.2016 / 01:54

1 answer

1

First of all you should set your filter to AndroidManifest.xml :

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
</intent-filter>

You need to add a scheme type at least by intent-filter also to define the type of url you can receive:

    <data android:scheme="http" />
    <data android:scheme="https" />
    <data android:scheme="file" />
</intent-filter>

Or create up to your own scheme , for example meuapp: :

    <data android:scheme="meuapp" />
</intent-filter>

Then within onCreate , you should run the command getIntent().getData() , example:

import android.net.Uri;

...

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final WebView minhaWebView = (WebView) findViewById(R.id.myWebView);

    final Uri urlintent = getIntent().getData();

    if (urlintent != null) {
        minhaWebView.loadUrl(urlintent.toString());
    }
}
    
12.12.2016 / 14:00