【发布时间】:2013-09-09 14:07:44
【问题描述】:
我正在尝试制作壁纸应用程序。我可以使用壁纸管理器设置壁纸。但是我想要的是,当我单击一个按钮时,应该会打开一个新意图,这应该是设置设备壁纸的默认方式。 (当我们尝试将图像表单库设置为墙纸时得到的屏幕,我们可以在其中选择图像区域等)。我已经护目镜,但找不到任何解决方案。
【问题讨论】:
标签: android
我正在尝试制作壁纸应用程序。我可以使用壁纸管理器设置壁纸。但是我想要的是,当我单击一个按钮时,应该会打开一个新意图,这应该是设置设备壁纸的默认方式。 (当我们尝试将图像表单库设置为墙纸时得到的屏幕,我们可以在其中选择图像区域等)。我已经护目镜,但找不到任何解决方案。
【问题讨论】:
标签: android
这是一个更好的解决方案,您不必指定目标应用程序;
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));
【讨论】:
使用"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());
}
【讨论】:
我知道它已经晚了,但有人想要,它对我有用。
final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
try {
wallpaperManager.setBitmap(yourImageView.getDrawingCache());
finish();
} catch (IOException e) {
e.printStackTrace();
}
【讨论】: