【问题标题】:Set Image as wallpaper using Intent使用 Intent 将图像设置为墙纸
【发布时间】:2016-09-14 07:36:15
【问题描述】:

我正在使用以下代码从可绘制图像中的图像设置壁纸:

Intent setAsIntent = new Intent();
setAsIntent.setDataAndType(uri, "image/*");
setAsIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
setAsIntent.setAction("android.intent.action.ATTACH_DATA");
Intent chooserIntent = Intent.createChooser(
        setAsIntent, "set as");

但是当startActivity时,它只显示一条消息:

没有应用可以执行此操作

【问题讨论】:

    标签: android wallpaper


    【解决方案1】:

    我确实发现了一种解决方法:

        Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setDataAndType(uri, "image/jpeg");
        intent.putExtra("mimeType", "image/jpeg");
        this.startActivity(Intent.createChooser(intent, "Set as:"));
    

    或尝试使用

    WallpaperManager
    
    
    wallpaperManager = WallpaperManager.getInstance(this);
    wallpaperDrawable = wallpaperManager.getDrawable();
    
    mImageView.setImageURI(imagepath);
    

    如果你有图像位图然后使用这个

    wallpaperManager.setBitmap(useThisBitmap);
    

    在您的清单文件中:

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

    【讨论】:

      猜你喜欢
      • 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
      相关资源
      最近更新 更多