<tfoot id='YIhhY'></tfoot>
    <bdo id='YIhhY'></bdo><ul id='YIhhY'></ul>
    <legend id='YIhhY'><style id='YIhhY'><dir id='YIhhY'><q id='YIhhY'></q></dir></style></legend>

    <small id='YIhhY'></small><noframes id='YIhhY'>

      <i id='YIhhY'><tr id='YIhhY'><dt id='YIhhY'><q id='YIhhY'><span id='YIhhY'><b id='YIhhY'><form id='YIhhY'><ins id='YIhhY'></ins><ul id='YIhhY'></ul><sub id='YIhhY'></sub></form><legend id='YIhhY'></legend><bdo id='YIhhY'><pre id='YIhhY'><center id='YIhhY'></center></pre></bdo></b><th id='YIhhY'></th></span></q></dt></tr></i><div id='YIhhY'><tfoot id='YIhhY'></tfoot><dl id='YIhhY'><fieldset id='YIhhY'></fieldset></dl></div>

        android - 从网络服务器保存图像并将其设置为壁纸

        时间:2023-07-08
        • <bdo id='fRGPa'></bdo><ul id='fRGPa'></ul>

                <i id='fRGPa'><tr id='fRGPa'><dt id='fRGPa'><q id='fRGPa'><span id='fRGPa'><b id='fRGPa'><form id='fRGPa'><ins id='fRGPa'></ins><ul id='fRGPa'></ul><sub id='fRGPa'></sub></form><legend id='fRGPa'></legend><bdo id='fRGPa'><pre id='fRGPa'><center id='fRGPa'></center></pre></bdo></b><th id='fRGPa'></th></span></q></dt></tr></i><div id='fRGPa'><tfoot id='fRGPa'></tfoot><dl id='fRGPa'><fieldset id='fRGPa'></fieldset></dl></div>

                <small id='fRGPa'></small><noframes id='fRGPa'>

                <legend id='fRGPa'><style id='fRGPa'><dir id='fRGPa'><q id='fRGPa'></q></dir></style></legend>
              • <tfoot id='fRGPa'></tfoot>

                  <tbody id='fRGPa'></tbody>

                1. 本文介绍了android - 从网络服务器保存图像并将其设置为壁纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  谁能提供一些关于如何从网络服务器保存图像并将其设置为墙纸的想法/指导?我正在开发一个需要这样做的 android 应用程序,我是 android 的新手.非常感谢.

                  Can anyone please provide me some idea/guidance on how to save an image from a webserver and set it as wallpaper? i am developing an android application which needs to do that and i am new in android. Thanks a lot.

                  我曾尝试编写自己的代码,但它不起作用,因为我在下载后找不到我的图片,但壁纸已更改为下载的图片.这是我现有的代码.

                  I had tried writing my own code but it doesn't work as i can't find my images after download but the wallpaper has change to the downloaded picture. here is my existing code.

                  Bitmap bmImg;
                  
                  void downloadFile(String fileUrl) {
                      URL myFileUrl = null;
                      try {
                          myFileUrl = new URL(fileUrl);
                      } catch (MalformedURLException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }
                      try {
                          HttpURLConnection conn = (HttpURLConnection) myFileUrl
                                  .openConnection();
                          conn.setDoInput(true);
                          conn.connect();
                          int length = conn.getContentLength();
                  
                          InputStream is = conn.getInputStream();
                  
                          bmImg = BitmapFactory.decodeStream(is);
                          // this.imView.setImageBitmap(bmImg);
                      } catch (IOException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }
                      try {
                          String filepath=Environment.getExternalStorageDirectory().getAbsolutePath(); 
                          FileOutputStream fos = new FileOutputStream(filepath + "/" + "output.jpg"); 
                          bmImg.compress(CompressFormat.JPEG, 75, fos);
                          fos.flush();
                          fos.close();
                  
                          Context context = this.getBaseContext();
                          context.setWallpaper(bmImg);
                      } catch (Exception e) {
                          //Log.e("MyLog", e.toString());
                          TextView tv = (TextView) findViewById(R.id.txt_name);
                          tv.setText(e.toString());
                      }
                  
                  }
                  

                  推荐答案

                  我曾尝试编写自己的代码,但它不起作用,因为我找不到我的图像下载后.这是我现有的代码.

                  I had tried writing my own code but it doesn't work as i can't find my images after download. here is my existing code.

                  您的代码会将图像保存在手机的 data/data/<your_app_package_name> 文件夹中.然后,您可以使用 WallpaperManager 实例 或执行 context.setWallpaper(bitmap)(已弃用)将您的位图设置为墙纸.

                  Your code would save the image in the data/data/<your_app_package_name> folder of the phone. You can then use either a WallpaperManager instance or do a context.setWallpaper(bitmap)(this is deprecated) to set your bitmap as the wallpaper.

                  这篇关于android - 从网络服务器保存图像并将其设置为壁纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:获取 Set<T> 中索引处的对象 下一篇:如何使用属性观察器观察具有 Swift 集合类型的特定元素?

                  相关文章

                  1. <legend id='0wquw'><style id='0wquw'><dir id='0wquw'><q id='0wquw'></q></dir></style></legend>

                    1. <i id='0wquw'><tr id='0wquw'><dt id='0wquw'><q id='0wquw'><span id='0wquw'><b id='0wquw'><form id='0wquw'><ins id='0wquw'></ins><ul id='0wquw'></ul><sub id='0wquw'></sub></form><legend id='0wquw'></legend><bdo id='0wquw'><pre id='0wquw'><center id='0wquw'></center></pre></bdo></b><th id='0wquw'></th></span></q></dt></tr></i><div id='0wquw'><tfoot id='0wquw'></tfoot><dl id='0wquw'><fieldset id='0wquw'></fieldset></dl></div>
                    2. <small id='0wquw'></small><noframes id='0wquw'>

                      <tfoot id='0wquw'></tfoot>
                        <bdo id='0wquw'></bdo><ul id='0wquw'></ul>