Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7400235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:13:08+00:00 2026-05-29T04:13:08+00:00

I am trying to setup a application to load URL in Webview and then

  • 0

I am trying to setup a application to load URL in Webview and then give the application the ability to set any image that is clicked to be set as a wallpaper.

So far I am able to load the URL and display the gallery.

I am pretty much stuck on how to set the click-able image was wallpaper.

Any help would be appreciated.

My code:

    package com.dg.rWallpapers;

import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

public class rWallpapersActivity extends Activity {
    WebView mWebView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mWebView = (WebView) findViewById(R.id.webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        /* mWebView.getSettings().setBuiltInZoomControls(true); */ //Removed I do not want zooming.
        mWebView.getSettings().setUseWideViewPort(true);
        mWebView.loadUrl("http://wall.dg.net?wallId=5");
        mWebView.setWebViewClient(new HelloWebViewClient(this));

        // Lookup R.layout.main
        RelativeLayout layout = (RelativeLayout)findViewById(R.id.ad);

        AdView adView = new AdView(this, AdSize.BANNER, "xxxx");

        // Add the adView to it
        layout.addView(adView);

        // Initiate a generic request to load it with an ad
        AdRequest request = new AdRequest();
        //request.setTesting(true);

        adView.loadAd(request);

    }


    public class HelloWebViewClient extends WebViewClient {

        private WallpaperManager mWallpaperManager;
        private Context mContext;

        public HelloWebViewClient(Context context) {
            mContext = context;
            mWallpaperManager = WallpaperManager.getInstance(context);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url.endsWith(".png") || url.endsWith(".jpg")) {
                try {
                    Bitmap b = downloadImage(url);
                    mWallpaperManager.setBitmap(b);
                    Toast.makeText(mContext, "Done!!", Toast.LENGTH_SHORT).show();
                    return true;
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            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;
        }
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
            mWebView.goBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }


}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:13:09+00:00Added an answer on May 29, 2026 at 4:13 am

    You could use a custom WebViewClient and implement the shouldOverrideUrlLoading() method to handle a click on your images in the activity. There, you can download the image and set it as a wallpaper.

    Here is an example for such a WebViewClient:

    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<String, Void, Bitmap>() {
    
                    @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;
        }
    }
    

    You add the WebViewClient to your WebView via setWebClient(new MyWebViewClient(this)) in your activity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to setup a simple timer that gets started from a Rails Application.
I am trying to set up my WPF application so that when an exception
I am trying to setup my application to use Spring and also an image
I am trying to setup a development environment for Linux C++ application. Because I'm
I am trying to setup an automated build of my Windows CE application. However,
I am trying to set up a basic Silverlight application to run behind the
I've been trying to no avail to set up a simple Struts2 application so
I'm trying to get a new Enterprise Application Project set up in Eclipse using
I'm trying to get a CakePHP application to work. For this, I've set up
I'm trying to setup rspec for testing in my rails application. I have created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.