1
I was looking for how to open links related to my domain as I did in my previous question and I got an answer.
I put that code on 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" />
<data android:scheme="http" />
<data android:host="oSeuDominio.???" />
<data android:host="www.oSeuDominio.???" />
<data android:pathPattern="/.*" />
</intent-filter>
Like when I click on a link related to my site, for example on Whatsapp and my appears in the list that can open that link.
The problem is that when I click the App it is a simple browser that works with Webview, does not open the link that was clicked, but the home page (index.php) of the site.
My Java code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (isOnline()) {
Toast.makeText(getApplicationContext(), "Carregando", Toast.LENGTH_SHORT).show();
//mWebView = (WebView) findViewById(R.id.webview);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.loadUrl("http://xxxx.xxx");
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setSupportZoom(false);
mWebView.setWebViewClient(new LinkWebViewClient());
mWebView.requestFocusFromTouch();
mWebView.setWebChromeClient(new WebChromeClient());
}
else
[...]
}
private class LinkWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView webview, String url)
{
if(isOnline()) {
Toast.makeText(getApplicationContext(), "Loading", Toast.LENGTH_SHORT).show();
webview.loadUrl(url);
return true;
}
else
{
Toast.makeText(getApplicationContext(), "Sem conexão", Toast.LENGTH_SHORT).show();
setContentView(R.layout.conexaofail);
return false;
}
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack())
{
if (isOnline()) {
mWebView.goBack();
return true;
}
else
{
setContentView(R.layout.conexaofail);
return false;
}
}
return super.onKeyDown(keyCode, event);
}
In this line
mWebView.loadUrl("http://xxxx.xxx");
you have the link to your website?– ramaral
That’s right, that’s it! Like when I open the App it first loads this url there.
– user41630