现在我们正在使用下面的代码从一些加载的图像中设置墙纸。
bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(this, R.string.set_wallpaper_complete_toast,Toast.LENGTH_SHORT).show();
return true;我们如何在上面的代码中使用getCropAndSetWallpaperIntent(Uri imageUri),以便它会询问设置墙纸和裁剪它的选项。
发布于 2016-01-23 14:23:56
public Uri getImageUri(Context inContext, Bitmap inImage) {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path = Images.Media.insertImage(inContext.getContentResolver(),
inImage, "Title", null);
return Uri.parse(path);
} 然后,
bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(getApplicationContext());
try {
Uri myImageUri = getImageUri(bitmap);
Intent intent = new Intent(myWallpaperManager.getCropAndSetWallpaperIntent(myImageUri));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
Toast.makeText(
this, R.string.set_wallpaper_complete_toast,Toast.LENGTH_SHORT).show();
return true; 发布于 2019-08-04 22:21:38
使用以下内容
val path: String = MediaStore.Images.Media.insertImage(contentResolver, bitmap, "wallpaper.jpg", null)
val intent = Intent(wallpaperManager.getCropAndSetWallpaperIntent(Uri.parse(path)))
startActivity(intent)https://stackoverflow.com/questions/34959999
复制相似问题