Android使用intent设置壁纸
我正在尝试制作墙纸应用程序。我可以使用墙纸管理器设置墙纸。但我想要的是,当我点击一个按钮时,一个新的意图应该打开,这应该是设置设备壁纸的默认方式。(当我们尝试将图像窗体库设置为墙纸时得到的屏幕,在那里我们可以选择图像的区域等)。我看了看,但找不到任何解决方案。使用Android使用intent设置壁纸,android,Android,我正在尝试制作墙纸应用程序。我可以使用墙纸管理器设置墙纸。但我想要的是,当我点击一个按钮时,一个新的意图应该打开,这应该是设置设备壁纸的默认方式。(当我们尝试将图像窗体库设置为墙纸时得到的屏幕,在那里我们可以选择图像的区域等)。我看了看,但找不到任何解决方案。使用“android.intent.action.SET_WALLPAPER”+设置壁纸应用程序的组件/类,以便应用程序能够处理意图 例如,AOSP内置墙纸应用程序如下所示: Intent intent = new Intent("andr
“android.intent.action.SET_WALLPAPER”
+设置壁纸应用程序的组件/类,以便应用程序能够处理意图
例如,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());
}
这是一个更好的解决方案,当你不必指定一个目标应用程序
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();
}
将图像设置为墙纸,上述代码将打开其他墙纸应用程序。