Hello, I'm developing an app with WebView
and I realized that it is not possible to download files from the web.
I tried to download a file from the dropbox,
It is possible that before downloading the file an alert will appear showing the following:
You want to download:
Nome-Do-Arquivo
and theSim
andNão
buttons
Code already done:
package br.and.browser;
import ...
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getActionBar().setDisplayShowHomeEnabled(false);
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().hide();
final EditText url = (EditText) findViewById(R.id.edittext_url);
final WebView myWebView = (WebView) findViewById(R.id.webview);
ImageButton Back = (ImageButton) findViewById(R.id.button_back);
ImageButton Next = (ImageButton) findViewById(R.id.button_next);
ImageButton Reload = (ImageButton) findViewById(R.id.button_reload);
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setSupportZoom(true);
myWebView.getSettings().getBuiltInZoomControls();
myWebView.invokeZoomPicker();
myWebView.loadUrl("https://www.google.com.br/");
Back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myWebView.goBack();
}
});
Next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myWebView.goForward();
}
});
Reload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myWebView.reload();
}
});
url.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
boolean handled = true;
if (actionId == EditorInfo.IME_ACTION_GO) {
myWebView.loadUrl(url.getText().toString());
return true;
}
return true;
}
});
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
WebView myWebView = (WebView) findViewById(R.id.webview);
if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
myWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}