代码之家  ›  专栏  ›  技术社区  ›  Slim C.

设置为墙纸意向对话框?

  •  0
  • Slim C.  · 技术社区  · 7 年前

    enter image description here

    2 回复  |  直到 7 年前
        1
  •  0
  •   aolphn    7 年前

    请尝试以下代码段:

    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);//add this if your targetVersion is more than Android 7.0+
    intent.setDataAndType(uri, "image/jpeg");
    intent.putExtra("mimeType", "image/jpeg");
    this.startActivity(Intent.createChooser(intent, "Set as:"));
    

    PS:uri应该从Android 7.0+中的FileProvider获取,如果您的targetVersion超过7.0+

        2
  •  0
  •   navylover    7 年前

    private void startWallpaper(){
        final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
        Intent chooser = Intent.createChooser(pickWallpaper,"set wallpaeper");
        startActivity(chooser);
    }
    

    here

    在清单文件中:

    <uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
    

    如果您想传递自己的img,可以如下操作:

    WallpaperManager wpm = WallpaperManager.getInstance(context);
    InputStream ins = new URL("absolute/path/of/image").openStream();
    wpm.setStream(ins);