Context menu for saving images in the Android web browser

I poured similar questions, but I can not find the answer. I want to be able to click on the images uploaded by the user for a long time in my web browser to save them (for example, you can in the browser). Any help?

Update:

Now the context menu appears with its own "Save Image" element. I can even successfully restart msgs. How can i save the image? Is an image that has been pressed for a long time transferred to my menu item?

public boolean onLongClick(View v) { openContextMenu(v); return true; } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.context, menu); } @Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); switch (item.getItemId()) { case R.id.save_image: Toast.makeText(this, "save failed", Toast.LENGTH_LONG).show(); return true; default: return super.onContextItemSelected(item); } } 
+4
source share
1 answer

First, register a WebView for context menus, for example: activity.registerForContextMenu(webView)

 @Override protected void onCreateContextMenu(ContextMenu menu) { super.onCreateContextMenu(menu); HitTestResult result = getHitTestResult(); MenuItem.OnMenuItemClickListener handler = new MenuItem.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { // do the menu action return true; } }; if (result.getType() == HitTestResult.IMAGE_TYPE || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) { menu.setHeaderTitle(result.getExtra()); menu.add(0, ID_SAVEIMAGE, 0, "Save Image").setOnMenuItemClickListener(handler); } 

To save images just use this

+7
source

Source: https://habr.com/ru/post/1379084/


All Articles