Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Set or Get phone wallpaper from your Application

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 323
    Comment on it

    To set or get the wallpaper of android phone from your application, we used WallpaperManager. This class provides access to the system wallpaper. By the help of this class you can get the current wallpaper of your phone inside your app and even can change the current wallpaper from your application. Also you can get the desired dimensions for the wallpaper.
    For more details about this class visit link

    First you need to create the instance of WallpaperManager and Handler

    private WallpaperManager wallpaperManager;
    private Handler handler;
    

    Now, inside onCreate()

     // instantiating wallpaperManager and handler
    wallpaperManager = WallpaperManager.getInstance(MainActivity.this);
    handler = new Handler();
    

    Method to set the wallpaper

    // set Wallpaper method
        private void setWallPaper()
        {
            Thread thread = new Thread() {
                public void run() {
                    WallpaperManager wallpaperManager = WallpaperManager.getInstance(MainActivity.this);
                    Drawable drawable = getResources().getDrawable(R.drawable.mclaren); 
                    try {
                        wallpaperManager.setBitmap("place your bitmap obj here");
    
                        handler.post(new Runnable() {
    
                            @Override
                            public void run() {
                                Toast.makeText(MainActivity.this, "WallPaper Changed successfully", Toast.LENGTH_SHORT).show();
                            }
                        });
    
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
    
                        handler.post(new Runnable() {
    
                            @Override
                            public void run() {
                                Toast.makeText(MainActivity.this, "WallPaper not changed", Toast.LENGTH_SHORT).show();
                            }
                        });
    
                    }
    
                }
            };
            thread.start();
        }
    

    To get the wallpaper

    mainImage.setImageDrawable(wallpaperManager.getDrawable());
    

    Note:- mainImage is the imagview in layout.
    Use the following permission in your manifest file

    <uses-permission android:name="android.permission.SET&#95;WALLPAPER"/>
    

 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: