2

我正在尝试开发 android 应用程序并且我想允许用户从动态壁纸中选择应用程序的背景。

现在,我如何从设备获取动态壁纸?

我想从设备中获取所有动态壁纸,可以吗?

我想从设备中获取所有动态壁纸,可以吗?

4

2 回答 2

3

您可以获得设备中所有动态壁纸的可用ResolveInfo列表:

 public List<ResolveInfo> GET_ALL_LIVE_WALLPAPERS () 
 {
    PackageManager m_package_manager = getPackageManager();
    List<ResolveInfo> available_wallpapers_list = 
         m_package_manager.queryIntentServices(
             new Intent(WallpaperService.SERVICE_INTERFACE),
             PackageManager.GET_META_DATA);

    for (int i = 0; i < available_wallpapers_list.size(); i++) {
        Log.i("TEST", " " + available_wallpapers_list.get(i).toString());
    }
    return available_wallpapers_list;
 }

available_wallpapers_list将包含与设备中动态壁纸数量相同的ResolveInfo数量。然后通过创建所需的新WallpaperInfo来选择列表中的任何一个:

 private void CHOOSE_LIVE_WALLPAPER (List<ResolveInfo> available_wallpapers_list)
 {
    WallpaperInfo info;
    int index = 0;
    try {
        info = new WallpaperInfo(this, available_wallpapers_list.get(index));
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    ComponentName component = info.getComponent();
    Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
    intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, component);
    startActivityForResult(intent, 155);
 }

如果您只想更酷并显示动态壁纸选择屏幕,请使用:

Intent intent = new Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
startActivityForResult(intent, 155);

最后,您可以为 4.3+ 设备调用 adb shell am 命令;

adb shell am start -n com.android.wallpaper.livepicker/.LiveWallpaperActivity

通过使用:

Runtime.getRuntime().exec("am start -n com.android.wallpaper.livepicker/.LiveWallpaperActivity");

干杯。

于 2015-09-09T12:45:50.480 回答
0
Intent intent = new Intent();
intent.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
startActivity(intent);
于 2015-06-03T11:55:27.597 回答