How to long press on image in webview

DelvisGrlln

New Member
Joined
Jul 25, 2016
Messages
1
Reaction score
0
Hi guy this is my first application android, i using android studio and i need the help. i long press in not show context menu to download the image, below I leave the code if someone is kind enough to give me help.<br />
<br />
<br />
<br />
import android.content.Context;<br />
import android.media.AudioManager;<br />
import android.os.Bundle;<br />
import android.support.v7.app.AppCompatActivity;<br />
import android.view.KeyEvent;<br />
import android.view.View;<br />
import android.webkit.WebChromeClient;<br />
import android.webkit.WebView;<br />
import android.webkit.WebViewClient;<br />
import android.widget.ProgressBar;<br />
<br />
public class MainActivity extends AppCompatActivity {<br />
WebView webView;<br />
ProgressBar progressBar;<br />
private AudioManager audio;<br />
<br />
@Override<br />
protected void onCreate(Bundle savedInstanceState) {<br />
super.onCreate(savedInstanceState);<br />
setContentView(R.layout.activity_main);<br />
audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);<br />
<br />
webView = (WebView) findViewById(R.id.webView);<br />
<br />
webView.setWebViewClient(new WebViewClient());<br />
<br />
webView.getSettings().setSupportZoom(true);<br />
webView.setVerticalScrollBarEnabled(true);<br />
webView.getSettings().setJavaScriptEnabled(true);<br />
webView.setHorizontalScrollBarEnabled(true);<br />
webView.getSettings().setLoadWithOverviewMode(true);<br />
webView.getSettings().setUseWideViewPort(true);<br />
//webView.getSettings().setBuiltInZoomControls(true);<br />
webView.loadUrl("Awesome Wallpapers - wallhaven.cc");<br />
<br />
<br />
<br />
//Barra de progreso<br />
progressBar = (ProgressBar) findViewById(R.id.progressBar);<br />
webView.setWebChromeClient(new WebChromeClient() {<br />
@Override<br />
public void onProgressChanged(WebView view, int progress) {<br />
progressBar.setProgress(0);<br />
progressBar.setVisibility(View.VISIBLE);<br />
MainActivity.this.setProgress(progress * 1000);<br />
progressBar.incrementProgressBy(progress);<br />
if (progress == 100) {<br />
progressBar.setVisibility(View.GONE);<br />
}<br />
}<br />
});<br />
<br />
<br />
/*Adding shortcut for MainActivity<br />
//on Home screen<br />
Intent shortcutIntent = new Intent(getApplicationContext(),<br />
MainActivity.class);<br />
<br />
shortcutIntent.setAction(Intent.ACTION_MAIN);<br />
<br />
Intent addIntent = new Intent();<br />
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);<br />
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut");<br />
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,<br />
Intent.ShortcutIconResource.fromContext(getApplicationContext(),<br />
R.drawable.ic_launcher));<br />
addIntent.putExtra("duplicate", false);<br />
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");<br />
getApplicationContext().sendBroadcast(addIntent);*/<br />
<br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
@Override<br />
public boolean onKeyDown(int keyCode, KeyEvent event) {<br />
<br />
switch (keyCode) {<br />
case KeyEvent.KEYCODE_VOLUME_UP:<br />
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,<br />
AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);<br />
return true;<br />
case KeyEvent.KEYCODE_VOLUME_DOWN:<br />
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,<br />
AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);<br />
return true;<br />
case KeyEvent.KEYCODE_BACK:<br />
if (webView.canGoBack()) {<br />
//if Back key pressed and webview can navigate to previous page<br />
webView.goBack();<br />
// go back to previous page<br />
return true;<br />
} else {<br />
finish();<br />
// finish the activity<br />
}<br />
return super.onKeyDown(keyCode, event);<br />
default:<br />
return false;<br />
}<br />
<br />
<br />
}<br />
<br />
<br />
<br />
}

Enviado desde mi SM-N910V mediante Tapatalk
 
Back
Top