I have an APK that is extremely large and uses very high-res files, and i was wondering if there was a method i could call to download those files and move them into the program's files. i can have the files uploaded to a server so that when the app starts up for the first time they will download and be placed in the correct folder. does anyone know how to do something like this?
Asked
Active
Viewed 225 times
1 Answers
0
Not sure about C# to be honest, but just as an example. I download images with;
String URL = new String(Globals.getServerURL()+"/getcompanylogo.asp");
File myExternalFile = new File(cxt.getExternalFilesDir(filepath), fileName);
ByteArrayOutputStream output=null;
if(Globals.CheckInternet()=="FOUND" && !Globals.getServerURL().isEmpty()){
try {
URL url = new URL(URL);
URLConnection urlConnection = url.openConnection();
urlConnection.setReadTimeout(5000);
urlConnection.setConnectTimeout(5000);
InputStream is = new BufferedInputStream(urlConnection.getInputStream());
byte[] buffer = new byte[8192];
int bytesRead;
output = new ByteArrayOutputStream();
while ((bytesRead = is.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
FileOutputStream fos = new FileOutputStream(myExternalFile);
fos.write(output.toByteArray());
fos.flush();
fos.close();
return "OK";
//bmp = createBitmap();
//return output.toByteArray();
} catch (MalformedURLException e) {
return "BadUrl";
} catch (ConnectTimeoutException e) {
return "ConnectionTimeout";
} catch (ConnectException e) {
return "ConnectionException";
} catch (IOException e) {
return "readwriteexception";
}
}
And the ASP page that serves the images contains;
<%Response.CacheControl = "no_cache" %>
<%Response.AddHeader "Pragma", "no_cache" %>
<%Response.Expires = -1 %>
<%
pathcode = (session("webpath")+"\companylogo.png")
response.buffer = true
'create a stream object
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile pathcode
Response.ContentType = "image/PNG"
Response.AddHeader "content-disposition", "inline;filename=image.png"
Response.BinaryWrite objStream.Read
'clean up..
objStream.Close
Set objStream = Nothing
%>
Hope that helps a little.

matty357
- 637
- 4
- 16
-
The asp part is vb script – matty357 Aug 12 '15 at 16:44
-
unfortunately i am not able to download files.do you have other examples? – CatWithTheNameOfADog Aug 13 '15 at 21:31
-
monogame does not seem to have the same stuff in system.net as XNA. – CatWithTheNameOfADog Aug 14 '15 at 00:34