In this tutorial, we will see how to create an Image Viewer and to set Wallpaper for Android
Objectives:
1) Design the UI with one ImageView component and two Button Components
2) Button Next shows the next image and other button Set Wallpaper sets the current image as wallpaper
3) Errors are shown using Toast.makeToast() method
Steps:
1) Desgin the screen as follows:
2) Set the permission for using Wallpaper in AndroidManifest.xml file
Objectives:
1) Design the UI with one ImageView component and two Button Components
2) Button Next shows the next image and other button Set Wallpaper sets the current image as wallpaper
3) Errors are shown using Toast.makeToast() method
Steps:
1) Desgin the screen as follows:
2) Set the permission for using Wallpaper in AndroidManifest.xml file
<uses-permission android:name="android.permission.SET_WALLPAPER" >
</uses-permission>
4) Implement the Next Button operation
int counter = 1;String currentImage = "";
ImageView iv = (ImageView) findViewById(R.id.
imageView1);
iv.setImageDrawable(getResources().getDrawable(
getResources().getIdentifier(
currentImage, "drawable",
getPackageName())));
}
catch (Exception e) {
Toast.makeText(
this, "Error Loading Image", Toast.LENGTH_SHORT)
.show();
}
5) Implement the set Wallpaper method
Handler
handler=new Handler();
Thread th =
new Thread() {
WallpaperManager wallpaperManager = WallpaperManager
.getInstance(MainActivity.
this);
wallpaperManager.setResource(
getResources().getIdentifier(
currentImage, "drawable",
getPackageName()));
Toast.makeText(MainActivity.
this, "Wallpaper set",
Toast.
LENGTH_SHORT).show();
}
});
}
catch (Exception e) {
Toast.makeText(MainActivity.
this,
Toast.
LENGTH_SHORT).show();
}
});
}
}
};
th.start();
}Result:


No comments:
Post a Comment