去往某个动态壁纸的预览页面,那里可以设置壁纸(4.12及其以上版本)

/**
     * 去往某个动态壁纸的预览页面,那里可以设置壁纸
     * 
     * @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, Configs.REQUEST_SET_LIVE_WALLPAPER);
    }

猜你喜欢

转载自flycatdeng.iteye.com/blog/2102977
今日推荐