How to make my webview open links from other apps

Asked

Viewed 655 times

0

I have a webview application and I want it to open links from other apps, I’ve put the Intent filter now I need to find the code that makes it open links from other apps. Thank you to those who answer.

  • You want other apps to "see" and be able to send a link to your app and from this your app can open such link?

  • Yes, I can already add my APP in the intention filter but I don’t know how to make my webview get the link sent from another APP, can help me?

1 answer

1

First you must define in your AndroidManifest.xml the filter:

<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 type of Scheme 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 even create your own Scheme, for example meuapp::

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

Then inside onCreate, you must 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());
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.