Download apk from web

Status
Not open for further replies.

Rusty

Well-Known Member
Licensed User
Longtime User
I'd like to maintain remote android devices without market apps. I would like to have my app automatically (upon startup) look at my website for a new version; download it (if present); install it and then restart. This is a private application so I don't want to go to the Android marketplace.
I can use the FTP lib to see the update is there and download it, but I'm not sure how to install it nor what location to which to download the apk.
Any suggestions? Thanks,
 

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks, Erel.
I'm not sure on a couple of things. (I've looked at the source code you suggested).
1. Where is the apk run from within the Android device?
2. Is it always named temp.apk?
3. What does "After downloading it you should send an intent that will install it. " mean? I'm not familiar with "an intent" and don't know how to instigate such.
4. When it is installed, is a copy of the temp.apk made somewhere within the Android device? If so, where?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. You should place the file on the storage card to make it available to the installer application.
2. You can name it whatever you want and you can delete the APK file after installing it.
3. See Sub HandleFileClose in B4A-Bridge (service module).
4. The apk gets installed in its own folder. Usually under /data/data/<package name>. This folder is private and cannot be accessed from other applications.
 
Upvote 0

lawboy

Member
Licensed User
Longtime User
Is it possible to show an example of how to compare the two .apk versions(with one on the unit and the other on a website) then download (save to sd card if apk on website is newer) and install the new apk ? I am trying to create a self updating app if a newer version is available on my website as well.

Thanks,
lawboy
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
apk updates

I was unable to find a way to get the date/time/size of a file on the FTP site. I ended up writing an not so elegant routine that checks the FTP site for a "control" file for the device by serial number. I download the control file and read its contents to find out what updates to the .apk and all databases etc. are needed for this device (serial number). This tells me what to download. I install the files after they are downloaded based upon what the file type is. if there is no control file, there are no updates or files needing downloading for the device.
This works for me because I'm supporting many devices each with differing database/file requirements and some with differing .apk applications.
Hope this helps. Please let me know if you come up with a better method.
 
Upvote 0

billy047

Member
Licensed User
Longtime User
Hi, This is another option that might help. implement a web page with a link that points to a directory on the server where the application. apk is located.

Then from the Android device browser, navigate to that page and when clicking the link, does the download, into the SD memory.

You go to your SD memory and you click on the file. apk you just download and install it. If a new version, then asks if it is replaced. That is all.

Only two things:
1 .- The web page or site should have implemented the following mime: extention =. apk Mime Type: application / vnd.android.package-archive "
2 .- Your device must have permission to accept external applications or unknown do it in Settings-> Applications
Sorry for my English, I hope I explained well the concept.
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
I considered the http method, but still, it requires you completely download the .apk file every time you start the application (or touch the button to check for updates) before you can determine if it even needs to be downloaded. If there were a way to check the date/time/version without the download, I think this would be more elegant and require fewer downloads of superfluous data.
Thanks for the suggestion though.
 
Upvote 0

Brad

Active Member
Licensed User
Longtime User
Here's an idea. Have your control file except the name of the control file would be the version number. With ftp perform a ListFiles and read the file name and compare with the installed app. No downloading necessary unless there is an update.
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Ok, the answer was in front of my face. I was using the ABFTP library instead of the FTP library. Although I think the ABFTP offers some better error handling, the FTP library offers the information about the files on the FTP host, such as timestamp and size. With this information and the File.LastModified (you can find out the date of the current .apk) Then with the FTP lib:
you connect:
myFTP.Initialize("MyFTP", txtFtp, txtPort, txtLogin, txtPassword)

Then you get a list of files from the FTP location:
MyFtp.List(FTPFileLocation)

This causes an event ..._ListCompleted to fire when the list is complete

Sub MyFTP_ListCompleted (ServerPath As String, Success As Boolean, Folders() As FTPEntry, Files() As FTPEntry)

dim APKDate as long
APKDate = File.LastModified("...my APK in my location..") 'get the date of the current .apk for comparison later

For i = 0 To Files.Length - 1 'roll through the list
Log(Files(i).Name & " size:" & files(i).Size & " date:" & datetime.dateparse(Files(i).Timestamp,False))
If ..my APK name.. = files(i).Name then ' it is the same .apk
If APKDate < Files(i).Timestamp Then ' it is newer than the one we have
...the file is newer do stuff here, like install the new .apk file
End if
End if
Next

This is event driven, so when you ask for a list, it doesn't come right back, you have to wait for a list complete event (the program keeps running and the event then fires) the ABFTP you get the list and process it without events.
This works very well but you have to keep things going while the events get ready and fire.
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
That's one of the nice things about the FTP lib. You can start the list, start the download(s) and go about your business while these occur. you can wait for the ListComplete,... events to fire and not have to stop your program while they are going on.
 
Upvote 0

dieterp

Active Member
Licensed User
Longtime User
Hi Guys

I have a similar situation as Rusty above and would like to know the best way to approach it. I have a private application that will not be released through the Google Apps store. Users will download it from a personal website. Different users will get different applications depending on their license, so when a user with a 'professional' licence downloads the professional version apk file, how can that file be saved on their device and installed from an internal location so that the user cannot simply send the apk file to other users?

Apologies if I am not understanding the explanation given above.

Regards
 
Upvote 0
Status
Not open for further replies.
Top