android - 从资源中设置壁纸

标签 android assets wallpaper

当我尝试从资源中设置壁纸时,完成工作需要时间,所以也许有更简单的方法而不是我的硬编码

public void Setwallpaper(int position , Context context) throws IOException{    
    AssetManager am = mContext.getAssets();
    nlist = am.list("Gallary");
     BufferedInputStream buf = new BufferedInputStream(am.open(nlist[position]));
     bitmap = BitmapFactory.decodeStream(buf);

     buf.close();
    WallpaperManager myWallpaperManager = WallpaperManager
            .getInstance(context);
    try {
        myWallpaperManager.setBitmap(bitmap);
        Toast.makeText(context, "Wallpaper set",
                0).show();
    } catch (IOException e) {
        Toast.makeText(context,
                "Error setting wallpaper", Toast.LENGTH_SHORT)
                .show();
    }
}

大约需要 3 秒才能完成此操作,而我看到其他应用程序能够在不到一秒的时间内完成此操作,如有任何建议,我将不胜感激,谢谢

最佳答案

试试这个

   WallpaperManager myWallpaperManager =WallpaperManager.getInstance(getApplicationContext());
    InputStream ims = getAssets().open("yourimage.jpg");
    myWallpapaerManager.setStream(ims)

关于android - 从资源中设置壁纸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15437362/

相关文章:

c# - 适合/填充图像?

android - 在 Android 中使图像在 x 轴上移动?

android - 添加自定义字体时无法解析方法 getAssets()

ssl - Symfony2 : assets_base_url by protocol or header

在Windows 7中更改壁纸的java代码

android - API 级别 3 的墙纸偏移量?

android - 自上次项目同步以来,Gradle 文件已更改。 IDE 正常工作可能需要项目同步

android - CollapsingToolbarLayout 折叠标题位置不正确

android - 来自 Android 蓝牙不安全 Rfcomm 的 "Service discovery failed"

image - Laravel Assets 网址