Showing posts with label easy way to set wallpaper in android. Android Beginners. Show all posts
Showing posts with label easy way to set wallpaper in android. Android Beginners. Show all posts

Friday, 6 September 2013

Set Wallpaper in Android

Easy Way to Android Set Wallpaper


There is a easy way to set the wallpaper from the resources folder of your application to the android smartphone.You can set it through program.


1. Add the permissions in the Android Manifest file.

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

2. MainActivity.java

import java.io.IOException;

import android.os.Bundle;
import android.app.Activity;
import android.app.WallpaperManager;
import android.view.Menu;

public class MainActivity extends Activity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  //android wallpaper manager
  WallpaperManager myWallpaperManager = WallpaperManager
    .getInstance(getApplicationContext());
  try {
   //set wallpaper picture from resource here
   myWallpaperManager.setResource(R.drawable.android_wallpaper);
   Toast.makeText(getApplicationContext(),"Success set as wallpaper",Toast.LENGTH_SHORT).show();
  } catch (IOException e) {
   Toast.makeText(getApplicationContext(),"Error on setting as wallpaper",Toast.LENGTH_SHORT).show();
  }
 }

}   

3. Now run your Application.(Dont Forget to put an image in res/drawable folder named android_wallpaper)

Thank you.