[英]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.