我正在尝试制作壁纸应用程序。我能够使用壁纸管理器来设置壁纸。但是我想要的是,当我点击一个按钮时,应该打开一个新的意图,这应该是设备上设置壁纸的默认方式。(当我们尝试将图库中的图像设置为墙纸时得到的屏幕,在那里我们可以选择图像的区域等等)。我已经搜索过了,但找不到任何解决方案。
我正在尝试制作壁纸应用程序。我能够使用壁纸管理器来设置壁纸。但是我想要的是,当我点击一个按钮时,应该打开一个新的意图,这应该是设备上设置壁纸的默认方式。(当我们尝试将图库中的图像设置为墙纸时得到的屏幕,在那里我们可以选择图像的区域等等)。我已经搜索过了,但找不到任何解决方案。
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));
我知道现在有点晚了,但如果有人需要,这对我很有效。
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
try {
wallpaperManager.setBitmap(yourImageView.getDrawingCache());
finish();
} catch (IOException e) {
e.printStackTrace();
}
使用"android.intent.action.SET_WALLPAPER"
+ 设置您的壁纸应用程序的组件/类,以便Intent由您的应用程序处理。
例如,对于AOSP内置的壁纸应用程序,它看起来像下面这样:
Intent intent = new Intent("android.intent.action.SET_WALLPAPER");
// Change the following line with that of your own app
intent.setClassName("com.android.launcher", "com.android.launcher2.WallpaperChooser");
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.wtf(TAG, "No activity found to handle " + + intent.toString());
}