Amin Kolivand
Amin Kolivand

Reputation: 31

show intent for Set as wallpaper or Set as contact picture

I want to set a Image View as a wallpaper or contact picture. I need to open a "chooser" for the User and I am using this code :

Uri uri = Uri.parse("android.resource://"+ this.getPackageName()+"/drawable/" +name+"jpg" );
    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:"));

This results in the following message: "no apps can perform this action."

Upvotes: 1

Views: 810

Answers (2)

Diwan Dhanvani
Diwan Dhanvani

Reputation: 291

use this code :

    Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
    startActivity(Intent.createChooser(intent, "Select Wallpaper"));
    You can create an item in contextMenu as Set as wallpaper in your app and when the user taps that item, you use this code.

    Call this method for setting the selected image as Wallpaper:

    public void setWallpaper() {

            Context context = this.getBaseContext(); 
            Bitmap mBitmap = BitmapFactory.decodeResource(getResources(),mImageIds[pos]);
            context.setWallpaper(mBitmap);
    }
    And add this permission in Android Manifest file:

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

Upvotes: 1

Ros&#225;rio P. Fernandes
Ros&#225;rio P. Fernandes

Reputation: 11344

Most apps don't recognize "jpeg" images nowadays. I recommend you look for apps with every image format. Use the code below:

Uri uri = Uri.parse("android.resource://"+ this.getPackageName()+"/drawable/" +name+"jpg" );
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setDataAndType(uri, "image/*");
    intent.putExtra("mimeType", "image/*");
    this.startActivity(Intent.createChooser(intent, "Set as:"));

Upvotes: 0

Related Questions