Reputation: 3
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();
}
}
Upvotes: 0
Views: 129
Reputation: 749
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);
}
Upvotes: 1