Search code examples
javaandroidandroid-imageandroid-wallpaper

image open with wallpaper app


i am creating a simple wallpaper app in which i have a image_view and a button.

image-view is showing a image, now what i want: i want to open image with wallpaper app on button click.

when i click button it should show all installed wallpaper app so i can choose any of them

to better understand see screenshot: this should happen when i click button

enter image description here this is my code:

package com.example.wallpaper_test;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class WallpaperScreenActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.wallpaper_layout);

        // image resource
        ImageView img = (ImageView) findViewById(R.id.imageView1);
        img.setImageResource(R.drawable.pop);

        // call installed wallpaper app to set wallpaper on button click
        Button b1 = (Button) findViewById(R.id.button1);
        b1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View vx) {

            }
        });

    }
}

Solution

  • This question has been answered here

        Uri uri = Uri.parse("URI_OF_YOUR_IMAGE");
    
        Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setDataAndType(uri, "image/jpeg");
        intent.putExtra("mimeType", "image/jpeg");
        this.startActivity(Intent.createChooser(intent, "Set as:"));