创建壁纸应用程序时出现问题。当我尝试设置壁纸时,出现以下错误。我想知道问题所在。我做错了什么?设置 setwallpaper 时出现此错误。如果有人知道这个问题的答案,请帮助我。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen);
Glide.with(getApplicationContext()).load(url).
transition(DrawableTransitionOptions.withCrossFade()).
apply(RequestOptions.centerCropTransform().
diskCacheStrategy(DiskCacheStrategy.DATA)).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
return false;
}
}).into(imageView);
}
public static WallpaperManager setMainScreenWallpaper(Context context, ImageView imageView, String message) {
Bitmap bitmap;
WallpaperManager manager = WallpaperManager.getInstance(context);
try {
bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
manager.setBitmap(bitmap, null, true, WallpaperManager.FLAG_SYSTEM);
}else {
manager.setBitmap(bitmap);
}
if(message.isEmpty()){
message = "Wallpaper set successfully";
}
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
} catch (NullPointerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}