简体   繁体   English

如何从服务器设置我的android应用背景?

[英]How can I set my android app background from a server?

I'm quite new to android programming and I have the following problem. 我对android编程很陌生,但遇到以下问题。 I want to be able to put an image om my server and then if I use my app it should use that image as a background. 我希望能够在服务器上放置一个图像,然后如果使用我的应用程序,则应将该图像用作背景。 From previous research I understand I cant save any files to the drawable file? 根据以前的研究,我知道我无法将任何文件保存到可绘制文件中吗? So is this even possible? 那有可能吗?

I am now this far: 我现在为止:

  URL url = new URL ("http://oranjelan.nl/oranjelan-bg.png");
  InputStream input = url.openStream();
  try { 
     String storagePath = Environment.getExternalStorageDirectory();
     OutputStream output = new FileOutputStream (storagePath + "/oranjelangb.png");
     try {
    byte[] buffer = new byte[1000000];
        int bytesRead = 0;
        while ((bytesRead = input.read(buffer, 0, buffer.length)) >= 0) {
        output.write(buffer, 0, bytesRead);
        }
     } finally {
      output.close();
        }
    } finally {
   input.close();
 }

But I get the following error @ String storagePath = Environment.getExternalStorageDirectory(); 但是我收到以下错误@ String storagePath = Environment.getExternalStorageDirectory(); The compiller says cannot convert file to string. 编译器说无法将文件转换为字符串。

It should be possible. 应该有可能。 Simple steps may include :- 简单的步骤可能包括:

1) Download image file from server, Store it to SDcard or assets folder. 1)从服务器下载图像文件,并将其存储到SDcard或资产文件夹中。 links for step 1 >> link1 link2 步骤1的链接>> link1 link2

2) Create a Bitmap from the file you downloaded. 2)从下载的文件创建位图。

3) Set that bitmap as a Background image. 3)将该位图设置为背景图像。

You can pick steps and search on SO there should be lots of answers available. 您可以选择步骤并进行搜索,因此应该有很多答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Android应用程序关闭后台进程? - How can I close background processes from my Android app? 如何将文件从服务器发送到Android应用程序? - How I can send a file from my server to an Android app? 如何使我的android应用在后台运行? - How can I make my android app run on the background? 我如何在后台关闭我的 android 应用程序的所有活动 - How i can close all activities of my android app in background 如何防止我的 Android 应用程序在后台停止? - How can I prevent my Android app from stopping when in background? 如何从我的Android应用程序向我的服务器发送日志信息? - how can I send log information from my Android app to my server? 如何防止任何人与我的服务器通信,除了我的Android应用程序 - How can I prevent anyone from communicating with my server except my Android app 当我的Android应用无法连接到服务器时,如何停止强制关闭它? - How can I stop my android app from force closing when it cant connect to my server? 如何为我的 Android 应用程序设置默认实例 URL - How can I set a default Instance URL for my Android App 如何在Android中将动作栏应用程序图标设置为onClickListner? - How can I set my actionbar app icon onClickListner in Android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM