【问题标题】:How to set wallpaper in Android? [duplicate]如何在Android中设置壁纸? [复制]
【发布时间】:2011-09-02 15:15:41
【问题描述】:

可能重复:
Android - how to set the wallpaper image

我已经开始在 Android 中开发应用程序。我想在 Android 中设置在后台运行的壁纸(使用服务),壁纸将在 5 分钟内在后台更改。我将图像文件保存在 Drawable 中。任何人都请发送设置wallpaer的代码并在5分钟后恢复它..

提前感谢。

【问题讨论】:

    标签: android


    【解决方案1】:

    Here is an example。但不幸的是,它对我不起作用。基本上我使用的是以下代码:

    代码:

        WallpaperManager myWallpaperManager = WallpaperManager
                .getInstance(this);  
        String imageFilePath = getFilePath(imageUri);
        Bitmap myBitmap = BitmapFactory.decodeFile(imageFilePath);
        if (myBitmap != null) {  
            try {  
                myWallpaperManager.setBitmap(myBitmap);  
            } catch (IOException e) {  
                showToast(ImageDisplay.this,
                        "Failed to set Backgroundimage");  
            }  
        } else {  
            showToast(ImageDisplay.this, "Failed to decode image.");  
        }
    

    据我所知,imageFilePath 是正确的(因为我也适用于不同的工作)。没有错误或异常。调用此应用后,我的手机背景为空。我做错了什么?

    【讨论】:

      【解决方案2】:
      is = new FileInputStream(new File(imagePath));
      bis = new BufferedInputStream(is);
      Bitmap bitmap = BitmapFactory.decodeStream(bis);
      Bitmap useThisBitmap = Bitmap.createScaledBitmap(
      bitmap, parent.getWidth(), parent.getHeight(), true);
      bitmap.recycle();
       if(imagePath!=null){
         System.out.println("Hi I am try to open Bit map");
      wallpaperManager = WallpaperManager.getInstance(this);
      wallpaperDrawable = wallpaperManager.getDrawable();
      wallpaperManager.setBitmap(useThisBitmap);
      

      .................................................. .. 如果你有图像 URI,那么使用这个

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

      .......如果有任何问题,请告诉我。

      【讨论】:

        【解决方案3】:

        您可能想查看WallpaperManager
        编写一个简单的服务,您可以使用Timer 定期更换壁纸。

        【讨论】:

        • 我无法通过关注 WallpaperManager 来执行此操作。请帮帮我…………
        • 如果您能说明为什么不能使用 WallpaperManager,将会有所帮助。您的目标是什么 API 级别?
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多