Download Code

Android Studio ImageView Example – Camera Wallpaper

In android studio imageview example you will learn about Image View,Camera and how to combine these two things to build an Android Wallpaper App.

So First i’ll give you some information about Image View and Camera.After that you will use these componenst within android studio imageview example application.


Image View displays an arbitrary image or icon.Image View is basically used to display captured image from camera in an application like Retrica.


The android framework provides different support of camera according to the devices.Camera is basically used to captured image and video.You can read further detail about Camera from Android DeveloperOfficial Website.

Create new android studio imageview example application project.After that go to your activity_main.xml file.Add imageview and two buttons.


android studio imageview,android studio imageview example,imageview example,imageview,camera,

After adding those UI components go to your class.Do the following steps.

  • Create variables for Image View and Buttons.
  • Create public method to get all id’s of UI Component and call it in onCreate() method.
  • Implement click event on camera and set wallpaper button.

When you click open camera button.It will start an activity for result means open camera using Intent with Media Store and it’s image capturing action.

When camera started and captured an image.After that you need a method to collect that image which you will call generally as data.For that purpose onActivityResult() method is used.In this method we will use bundle to get image using getExtra() method and then store it in Bitmap variable.Then at last set that Bitmap to Image View which you add in xml file.

Next image will display within Image View.Then set wallpaper by calling this method setWallpaper().

package com.example.anonymous.studiowallpaper;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    ImageView pic; // image view variable to set captured image
    Button camera,setwall;  // button variables to open cam and set wallpaper
    Intent cameraIntent; // intent variable for starting cam
    Bitmap wall;         // variable to store data which image
    protected void onCreate(Bundle savedInstanceState) {

    // public method to get all id's of UI Components
    public void initialize(){
        pic = (ImageView) findViewById(;
        camera = (Button) findViewById(;
        setwall  =(Button) findViewById(;
        camera.setOnClickListener(this);   // click listener
        setwall.setOnClickListener(this); // click listener

    public void onClick(View v) {
        // TODO Auto-generated method stub
            // set wallpaper button case
                try {
                } catch (IOException e) {
                    // TODO Auto-generated catch block
            // open cam button case
                // open cam to capture image and return
                cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                // starting activity and accept return data second parameter will collect image which is our data
                startActivityForResult(cameraIntent, 0);

    // this method is used to get data which is our image right now in this project
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        // RESULT_OK means operation succeeded
        if(resultCode == RESULT_OK){
            // Bundle is used to get intent data using getExtra method
            Bundle b = data.getExtras();
            // getting bitmap data and store in wall bitmap variable
            wall = (Bitmap) b.get("data");
            // setting bitmap to image view displaying


Next you must have SET_WALLPAPER permission in your Android Manifest.

android studio imageview,android studio imageview example,imageview example,imageview,camera,

Run android studio imageview example application project and open cameras,capture image.It will display within the imageview.

android studio imageview,android studio imageview example,imageview example,imageview,camera,


That’s it.

I hope you have got every step clearly of android imageview example tutorial.

Don’t forget to leave your feedback thanks.