3

I'm trying to change wallpaper on galaxy sIII (ICS os) device I'm using 1280x1440 jpeg image by this code:

<uses-permission android:name="android.permission.SET_WALLPAPER"/>

....

Bitmap m = BitmapFactory.decodeByteArray(data, 0, data.length);
WallpaperManager.getInstance(this).setBitmap(m);

which is not working and following not working also:

Bitmap m = BitmapFactory.decodeResource(getResources(), R.drawable.data_img);
WallpaperManager.getInstance(this).setBitmap(m);

but when i use this:

WallpaperManager.getInstance(this).setResource(data_img);

it was work perfectly but my case is download some image data save it as bitmap then set it as wallpaper. so loading resources is not functional in my case.

any help, thanks in advance.

Evert
  • 93,428
  • 18
  • 118
  • 189
someone
  • 227
  • 6
  • 18

3 Answers3

9

You can find the documentation here.

You have to use public void setStream (InputStream data) method:

InputStream ins = new URL("absolute/path/of/image").openStream();
WallpaperManager wpm = WallpaperManager.getInstance(context);
wpm.setStream(ins);

OR, if you have image URI then use:

WallpaperManager wpm = WallpaperManager.getInstance(context);
wpm.setResource(Uri.of.image);
Tudor Luca
  • 6,259
  • 2
  • 29
  • 44
0

thanks @Tudor Luca its working fine..

ins = new URL("file://"+Environment.getExternalStorageDirectory()+"/gst/chhota.jpg").openStream();
WallpaperManager wpm = WallpaperManager.getInstance(getBaseContext());
wpm.setStream(ins);
kleopatra
  • 51,061
  • 28
  • 99
  • 211
Dipak Sonnar
  • 193
  • 2
  • 7
0

try this...

  private static boolean connectToNewWifiConfig(final WifiConfiguration wc, Context context)
    {
        wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        boolean success = false;
        final int actNetId = wifi.getConnectionInfo().getNetworkId();
        WifiInfo wifiInfo = wifi.getConnectionInfo();
        String prevNetworkSSID = wifiInfo.getSSID();
        int netId = wifi.addNetwork(wc);
        if (netId != ApplicationConstants.INVALID_NETWORK_ID)
        {
            success = wifi.saveConfiguration();
        }
        return success;
    }

it works for me make sure you pass right wificonfiguration , wificonfiguration will contain

wifiConfig = new WifiConfiguration();
        wifiConfig.SSID = "\"".concat(networkSSID).concat("\"");
        wifiConfig.status = WifiConfiguration.Status.ENABLED;
        wifiConfig.hiddenSSID = true;
        wifiConfig.priority = 40;
tanmeet
  • 220
  • 2
  • 11