1
In the code below, link with mcpack are open in the Webview application, however, sometimes it opens in the default browser, which I do?
@Override
public boolean shouldOverrideUrlLoading(WebView view, final String url)
{
if (url.contains("https://www.mediafire.com/file/") || (url.endsWith("mcpack") || (url.contains("https://www.mediafire.com/download_repair.php") || (url.contains("http://engine.addroplet.com/")) ))) { // Could be cleverer and use a regex
mWebView.loadUrl(url);
return false;
}
mWebView.stopLoading();
mWebView.goBack();
final AlertDialog alertDialog = new AlertDialog.Builder(Textures.this).create();
alertDialog.setTitle("Navegador");
alertDialog.setMessage("Deseja abrir o navegador?");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Sim", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
});
alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Não", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
alertDialog.dismiss();
}
});
alertDialog.show();
return false;
}
Did not solve, continue opening in the browser :-(
– Daniel
@Daniel Vale just you put some
Log.din your code to check if you are actually entering this method and thisif. Something likeLog.d("TESTE-WEBVIEW", "ENTROU NO METODO "+url )at the beginning of the function and another within theifLog.d("TESTE-WEBVIEW", "ENTROU NO IF"+url )and see if it appears inLogcat– Icaro Martins
I tried twice, the first time you didn’t download, and the second time you asked to open the browser. ENTROU NO METODO https://www.mediafire.com/file/2t8pfp3o8eo9tm3/Dark_Mode_v1.8.0_r-2.mcpack/file TESTE-WEBVIEW ENTROU NO METODO http://download1638.mediafire.com/x1549vkcyldg/2t8pfp3o8eo9tm3/Dark+Mode+v1.8.0+r.2.mcpack TESTE-WEBVIEW ENTROU NO METODO https://www.mediafire.com/file/2t8pfp3o8eo9tm3/Dark_Mode_v1.8.0_r-2.mcpack/file
– Daniel
the
ifwill not work because it does not end withmcpack, you’ll have to usecontainsinstead ofendsWith– Icaro Martins
Not really, but when the user click on download will open another link, in it the end contains mcpack.
– Daniel
Thank you very much, it works!
– Daniel