Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Set WallPaper in Android

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 176
    Comment on it

    Hello Friends,
    Here I am writing code to set wallpaper in android.

    Its very applicable in many scenarios like after downloading an image we have to give an option to set it as wallpaper or make functionality to create App wallpaper to phone wallpaper.

    First of all we need to declare following permission in manifest file:

    uses-permission android:name="android.permission.SET_WALLPAPER">
    uses-permission android:name="android.permission.SET_WALLPAPER_HINTS">
    

    We use Displaymatrics because we have some reasons like we need to set image to every devices or every screen size.
    As we know that In Android, We deal with so many screen size devices.
    // Convert image to Bitmap
    Bitmap imageBm = BitmapFactory.decodeStream(getResources().openRawResource(R.id.wall_img));
     DisplayMetrics dm = new DisplayMetrics(); 
     getWindowManager().getDefaultDisplay().getMetrics(dm);
     int screenHight = dm.heightPixels; 
     int screenWidth = dm.widthPixels;
    
    WallpaperManager myWallManager = WallpaperManager.getInstance(this); 
     try {
     myWallManager.setBitmap(imageBm);
    
    wallpaperManager.suggestDesiredDimensions(screenWidth, screenHight);
     Toast.makeText(this, "Yesss. Got it Wallpaper Changed", Toast.LENGTH_LONG).show();
     } catch (IOException ioe) {
     ioe.printStackTrace();
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: