/**
* 去往某个动态壁纸的预览页面,那里可以设置壁纸
*
* @param context
* @param packageName
* 动态壁纸的包名
* @param classFullName
* 动态壁纸service类的类全名
*/
@SuppressLint("InlinedApi")
public static void startLiveWallpaperPrevivew(Context context,
String packageName, String classFullName) {
ComponentName componentName = new ComponentName(packageName,
classFullName);
Intent intent = new Intent(
WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
componentName);
intent.putExtra("test", "test");
context.startActivity(intent);
}
对于低于4.1.2版本的,经过苦苦的研究和寻找还是找不到直接去往预览页面的方法,而且看别人的一个这个的应用也不是直接进入到预览页面,而是先进入选择页面,再进入到预览页面。可以通过action:ACTION_LIVE_WALLPAPER_CHOOSER进入
修改之后的方法:(action尽量用字符串,而不是从WallpaperManager获得)
/**
* 去往某个动态壁纸的预览页面,那里可以设置壁纸
*
* @param context
* @param packageName
* 动态壁纸的包名
* @param classFullName
* 动态壁纸service类的类全名
*/
public static void startLiveWallpaperPrevivew(Activity activity, String packageName, String classFullName) {
ComponentName componentName = new ComponentName(packageName, classFullName);
Intent intent;
if (android.os.Build.VERSION.SDK_INT < 16) {
intent = new Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
} else {
intent = new Intent("android.service.wallpaper.CHANGE_LIVE_WALLPAPER");
intent.putExtra("android.service.wallpaper.extra.LIVE_WALLPAPER_COMPONENT", componentName);
}
activity.startActivityForResult(intent, 0);
}

本文介绍了一种在不同Android版本中启动动态壁纸预览页面的方法。针对4.1.2版本以上的设备,可以直接跳转至预览页面进行壁纸设置;而对于更早版本,则需通过选择器进入。代码示例展示了如何根据目标设备的SDK版本,选择合适的Intent action来实现这一功能。
2万+

被折叠的 条评论
为什么被折叠?



