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.
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.
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());
}
}