Update Application APK

Bill Norris

Active Member
Licensed User
Longtime User
Is it possible to use http service to replace the apk of a currently running application? Will ultimately have approx 20 devices at same location running the app, and would like to simplify updating the app to all devices.
 
Yes, I already do this without a problem. In fact, I'm reinstalling the apk after downloading it using httpUtils, from inside the app. Except if you mean something else.
 
Upvote 0
RE:

That's pretty much what I am wanting to do. So, the app is running, and a new APK is downloaded. Does the new one simply overwrite the existing one, even though it is running? If so, what step(s) are necessary to close out the currently running app and start the new version?
 
Upvote 0
I'm pretty sure that you can only install an APK file that is saved to the device external memory.

Here's some code i used to update the currently running app:

Code: Copy
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_VIEW, "file:///sdcard/temp.apk")
Intent1.SetType("application/vnd.android.package-archive")
StartActivity(Intent1)

The user will be prompted to give permission to install the APK - i don't think there's anyway to install an APK without the user being asked permission.

Martin.
 
Upvote 0
RE:

Sorry to appear so clueless, but: when I download the new APK, where should I save it to -- defaultexternal, defaultinternal, etc.
 
Upvote 0
Sorry to appear so clueless, but: when I download the new APK, where should I save it to -- defaultexternal, defaultinternal, etc.
I use defaultexternal but I think it's a matter of choice :)

Did you arrange your code or perhaps I should post here an example of how I currently do this?
 
Upvote 0
I saved the APK to File.DirRootExternal and it installs ok.

One thing your can do when your app starts (FirstTime is True) is to check if your APK exists where you save your new APK to.
Delete it if it exists and keep the external memory tidy.

Martin.
 
Upvote 0
That's works perfect to install the update, but what about re-start the app after the installation?

Thanks
 
Upvote 0
That's works perfect to install the update, but what about re-start the app after the installation?

Thanks

Hi, this works for me great

Code: Copy
AddReceiverText(service1, 
<intent-filter>
    <action android:name="android.intent.action.PACKAGE_REPLACED" />
    <data android:scheme="package" />
</intent-filter>)
 
Upvote 0
Where did you put that? I'm doing the updating right after download of the package in a Sub on the Main module.

Everything wroks and the device is asking to do the installation of the new package and is showing all the messages, but after the new package is installed nothing re-start again so I have to push the app icon again to make it start.

Thanks
 
Upvote 0
I'm pretty sure that you can only install an APK file that is saved to the device external memory.

Here's some code i used to update the currently running app:

Code: Copy
Dim Intent1 As Intent
Intent1.Initialize(Intent1.ACTION_VIEW, "file:///sdcard/temp.apk")
Intent1.SetType("application/vnd.android.package-archive")
StartActivity(Intent1)

The user will be prompted to give permission to install the APK - i don't think there's anyway to install an APK without the user being asked permission.

Martin.
Hello Martin
Could you provide the code to install APK without user permission(silent mode ) for rooted devices?
 
Upvote 0
Hi all,

maybe the following link could be useful : AppUpdating library
Be sure to use version 1.25 which comes complete of example and source code.

Umberto
 
Upvote 0
Hi all,

maybe the following link could be useful : AppUpdating library
Be sure to use version 1.25 which comes complete of example and source code.

Umberto
Whai I need actually is the code that will launch the already existed APK and the process will not be interrupted to get user permission. It is possible only for rooted devices and I need the code like that:
Dim Intent1 AsIntent
Intent1.Initialize(Intent1.ACTION_VIEW, "file:///sdcard/temp.apk")
Intent1.SetType("application/vnd.android.package-archive")StartActivity(Intent1)

but with superuser privilegies.
 
Upvote 0
Hi Evgeny,

have a look here.
They suggest a different approach that seems to work.
 
Upvote 0
Hi
I think I have found a way to automatically update the APK without user confirmations and automatically restart it(for rooted devices)
Code: Copy
Sub btnAPK_Click
 
Dim Command, Runner As String
Dim StdOut, StdErr As StringBuilder
Dim Result As Int
Dim Ph As Phone
Dim MyPath as string = File.DirRootExternal & "/B4A"
 
Runner = File.Combine(File.DirInternalCache, "runner")
Command = File.Combine(File.DirInternalCache, "command")
File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
File.WriteString(File.DirInternalCache, "command", "pm install -r "& File.Combine(MyPath, "Your.apk") & CRLF & _
                "am start -n " & "b4a.your/b4a.your.main" & CRLF & "Exit")  'Any commands via crlf, and exit at end
 
StdOut.Initialize
StdErr.Initialize
Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
Msgbox(StdOut.tostring, "")
 
   
End Sub

"Your" is a name of your APK
 
Upvote 0
Hi
I think I have found a way to automatically update the APK without user confirmations and automatically restart it(for rooted devices)
Code: Copy
Sub btnAPK_Click

Dim Command, Runner As String
Dim StdOut, StdErr As StringBuilder
Dim Result As Int
Dim Ph As Phone
Dim MyPath as string = File.DirRootExternal & "/B4A"

Runner = File.Combine(File.DirInternalCache, "runner")
Command = File.Combine(File.DirInternalCache, "command")
File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
File.WriteString(File.DirInternalCache, "command", "pm install -r "& File.Combine(MyPath, "Your.apk") & CRLF & _
                "am start -n " & "b4a.your/b4a.your.main" & CRLF & "Exit")  'Any commands via crlf, and exit at end

StdOut.Initialize
StdErr.Initialize
Result = Ph.Shell("sh", Array As String(Runner), StdOut, StdErr)
Msgbox(StdOut.tostring, "")

  
End Sub

"Your" is a name of your APK

I will try, anyway, it works?
 
Upvote 0
Back
Top