【问题标题】:How to make user set wallpaper manually?如何让用户手动设置壁纸?
【发布时间】:2019-10-31 20:11:11
【问题描述】:

我确实设置了墙纸功能,但不是像这样手动设置的 set wallpaper

代码:                        

private void setWallpaper()
{
    Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
    WallpaperManager manager = WallpaperManager.getInstance(getApplicationContext());
    try {
        manager.setBitmap(bitmap);
        Toast.makeText(ViewWallpaperActivity.this,"Done!",LENGTH_LONG).show();
    } catch (IOException e) {
        Toast.makeText(ViewWallpaperActivity.this,"Error!",LENGTH_LONG).show();
    }
}

【问题讨论】:

标签: android


【解决方案1】:

试试这个设置壁纸表的代码:

private void setWallpaper(){
    Uri uri = getImageUri(getApplicationContext(), bitmap);
    Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.setDataAndType(uri, "image/jpeg");
    intent.putExtra("mimeType", "image/jpeg");
    startActivity(Intent.createChooser(intent, "Set as:"));
}
public Uri getImageUri(Context inContext, Bitmap inImage) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    inImage.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
    String path = MediaStore.Images.Media.insertImage(inContext.getContentResolver(), inImage, "Title", null);
    return Uri.parse(path);
}

【讨论】:

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