Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could use a custom <a href="http://developer.android.com/reference/android/webkit/WebViewClient.html" rel="nofollow"><code>WebViewClient</code></a> and implement the <code>shouldOverrideUrlLoading()</code> method to handle a click on your images in the activity. There, you can download the image and set it as a wallpaper.</p> <p>Here is an example for such a <code>WebViewClient</code>:</p> <pre><code>public class MyWebViewClient extends WebViewClient { private WallpaperManager mWallpaperManager; private Context mContext; public MyWebViewClient(Context context) { mContext = context; mWallpaperManager = WallpaperManager.getInstance(context); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (url.endsWith(".png") || url.endsWith(".jpg") || url.endsWith(".jpeg")) { new AsyncTask&lt;String, Void, Bitmap&gt;() { @Override protected Bitmap doInBackground(String... params) { try { return downloadImage(params[0]); } catch (IOException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Bitmap result) { if (result != null) { try { mWallpaperManager.setBitmap(result); Toast.makeText(mContext, "Done!!", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); } } } }.execute(url); return true; } return false; } private Bitmap downloadImage(String fileUrl) throws IOException { try { HttpGet httpRequest = new HttpGet(new URL(fileUrl).toURI()); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = (HttpResponse) httpClient.execute(httpRequest); BufferedHttpEntity buffer = new BufferedHttpEntity(response.getEntity()); return BitmapFactory.decodeStream(buffer.getContent()); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return null; } } </code></pre> <p>You add the WebViewClient to your WebView via <code>setWebClient(new MyWebViewClient(this))</code> in your activity.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload