【问题标题】:How to set the phone wallpaper through an intent如何通过intent设置手机壁纸
【发布时间】:2017-09-08 22:23:05
【问题描述】:

我有一些图像保存在手机内部存储的文件路径中,如下所示:

/storage/emulated/0/myApp/FILENAME.jpg

我想打开一个意图,以便用户可以使用他选择的应用设置手机壁纸。我尝试的每个代码都根本不起作用或仅适用于某些应用程序。谢谢。

【问题讨论】:

    标签: android android-intent android-wallpaper


    【解决方案1】:

    你可以通过打开这个intent来设置sdcard或手机中的任何图片:

    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

    P.S:您需要为 SET_WALLPAPER 添加权限,适用于 android 6+

    更新:

    您还可以使用以下方法将设置壁纸打开为对话框:

    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,例如应该通过 GooglePhotos 或手机的启动器设置壁纸
    • 您不能再使用GooglePhotos设置壁纸
    • 是的,我可以,例如,我现在使用 QuickPic 通过 Google 照片设置壁纸。我不知道如何在我的应用中做同样的事情。
    • 您的代码成功打开了意图对话框,但是当我单击某个应用时,该应用无法启动。
    • 我找到了解决办法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多