0

I do set wallpaper function but it's not manually like this set wallpaper

Code:                        

private void setWallpaper()
{
    Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
    WallpaperManager manager = WallpaperManager.getInstance(getApplicationContext());
    try {
        manager.setBitmap(bitmap);
        Toast.makeText(ViewWallpaperActivity.this,"Done!",LENGTH_LONG).show();
    } catch (IOException e) {
        Toast.makeText(ViewWallpaperActivity.this,"Error!",LENGTH_LONG).show();
    }
}
Mohan Singh
  • 1,142
  • 3
  • 15
  • 30
Mu PK
  • 3
  • 4

1 Answers1

1

Try this code for Set wallpaper sheet:

private void setWallpaper(){
    Uri uri = getImageUri(getApplicationContext(), bitmap);
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setDataAndType(uri, "image/jpeg");
    intent.putExtra("mimeType", "image/jpeg");
    startActivity(Intent.createChooser(intent, "Set as:"));
}
public Uri getImageUri(Context inContext, Bitmap inImage) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
    return Uri.parse(path);
}
Wang Liang
  • 4,244
  • 6
  • 22
  • 45
Kuvonchbek Yakubov
  • 558
  • 1
  • 6
  • 16