我正在尝试开发Android应用程序我希望允许用户从动态壁纸中选择应用程序的背景。
现在,我如何从设备上获取动态壁纸?
我想从设备上获取所有动态壁纸,我能做到吗?
答案 0 :(得分: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");
干杯。
答案 1 :(得分:0)
Intent intent = new Intent();
intent.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
startActivity(intent);