使用意图设置Android壁纸

4

我正在尝试制作壁纸应用程序。我能够使用壁纸管理器来设置壁纸。但是我想要的是,当我点击一个按钮时,应该打开一个新的意图,这应该是设备上设置壁纸的默认方式。(当我们尝试将图库中的图像设置为墙纸时得到的屏幕,在那里我们可以选择图像的区域等等)。我已经搜索过了,但找不到任何解决方案。

3个回答

1
这是一个更好的解决方案,您无需指定目标应用程序;
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));

将一张图片设置为壁纸,以上代码会打开其他壁纸应用程序。 - Shadab K

0

我知道现在有点晚了,但如果有人需要,这对我很有效。

final WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
    final Drawable wallpaperDrawable = wallpaperManager.getDrawable();
    try {
        wallpaperManager.setBitmap(yourImageView.getDrawingCache());
        finish();
    } catch (IOException e) {
        e.printStackTrace();
    }

0

使用"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());
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接