如何通过一个意图
问题描述:
我有些图像保存在一个文件路径,手机内部存储,看起来像这样设置手机壁纸:如何通过一个意图
/storage/emulated/0/myApp/FILENAME.jpg
我想开一个意图,以便用户可以设置手机壁纸与他的应用程序的选择。我尝试过的每个代码根本不起作用,或者仅适用于某些应用程序。谢谢。
答
您可以通过打开这个意图设置任何图像中的SD卡或电话:
Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
startActivity(Intent.createChooser(intent, "Select Wallpaper"));
好心添加权限过于:
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
更多选项查看this answer
PS:您需要为Android 6+添加对SET_WALLPAPER的许可
更新:
你也可以开集壁纸为对话框使用:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(imageUri, "image/*");
intent.putExtra("jpg", "image/*");
startActivityForResult(Intent.createChooser(intent,
getString(R.string.set_as)), REQUEST_ID_SET_AS_WALLPAPER);
嗨,我不想使用WallpaperManager,壁纸应该例如通过Google相册设置或手机的发射 – David
你不能再设置壁纸使用[GooglePhotos](https://www.reddit.com/r/Nexus6P/comments/624vkl/can_no_longer_set_wallpaper_using_google_photos/) –
是的,我可以,例如现在我使用QuickPic来设置壁纸通过Google相册。我不知道如何在我的应用程序中做同样的事情。 – David