- Posts no fórum: 1
21/09/2017, 16:08:51 via Web
21/09/2017 16:08:51 via Web
Ola pessoal,
sou iniciante em android e gostaria de uma ajuda.
O cenário é o seguinte:
estou desenvolvendo um app que simplesmente carrega um site da web fullscreen no app.
Porém quando clico no link de download de arquivo, o link é aberto fora do app no chrome.
Queria que o download fosse feito dentro do app, seja com um alert, ou barra de progresso do download.
Alguem pode me ajudar?
segue o codigo:
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebChromeClient; //aadd
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.DownloadListener; //aadd
import android.content.Intent; //aadd
import android.net.Uri; //add
public class Main extends Activity {
public boolean onKeyDown(int keyCode, KeyEvent event){
WebView web = (WebView)findViewById(R.id.webSite);
if(keyCode == KeyEvent.KEYCODE_BACK && web.canGoBack()){
web.goBack();
return true;
}else{
getApplication().onTerminate();
return false;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
//setTitle("IC");
setContentView(R.layout.activity_main);
if(conectado()){
WebView web = (WebView)findViewById(R.id.webSite);
web.clearCache(true);
//web.getSettings().setBuiltInZoomControls(true);
//web.getSettings().setSupportZoom(true);
web.setWebViewClient(new ClientWeb());
web.getSettings().setJavaScriptEnabled(true);
web.getSettings().setDomStorageEnabled(true);//add
web.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);//add
web.setWebChromeClient(new WebChromeClient());//add
web.addJavascriptInterface(this, "Exemplo");//add
web.getSettings().setDatabaseEnabled(true);//add
web.getSettings().setDomStorageEnabled(true);//add
web.getSettings().setAllowFileAccess(true);//add
web.getSettings().setAllowContentAccess(true);//add
web.getSettings().setAllowFileAccess(true);//add
web.setDownloadListener(new DownloadListener() {
@Override
public void onDownloadStart(String url, String userAgent,
String contentDisposition, String mimetype,
long contentLength) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
}
});
web.loadUrl("AQUI COLOCO A URL");