Welcome! Log In Create A New Profile

Advanced

WM22: Android - update user app without Playstore

Posted by Peter Muckle 
Re: WM22: Android - update user app without Playstore
January 08, 2020 09:39AM
Hi everyone,
I am also interested in this method of updating applications.
Have you found a final solution to it?
TIA
Re: WM22: Android - update user app without Playstore
January 08, 2020 06:24PM
Hello everyone

Here is the code that works for the question listed here:

PROCEDURE Auto_update()

dtVerzija_nova is DateTime
dtVerzija_stara is DateTime

nKonekcijaID is int
nKonekcijaID = FTPConnect("ftpserver","ftpuser","ftppasw",21)
IF nKonekcijaID <> -1 THEN
IF FTPFileExist(nKonekcijaID,"/APK/Infos.apk") THEN
dtVerzija_nova = FTPDateTime(nKonekcijaID,"/APK/Infos.apk")
dtVerzija_stara = fDateTime(fExeDir()+"\Infos.apk")
IF dtVerzija_nova <> dtVerzija_stara THEN
IF FTPGet(nKonekcijaID,"/APK/Infos.apk",fExeDir()) THEN
IF ShellExecute(fExeDir()+"\Infos.apk") THEN
ToastDisplay("Instalirana je najnovija verzija aplikacije")
END
END
END
END
FTPDisconnect(nKonekcijaID)
ELSE
//Error()
END


REMARK:

WM 22 - This code works until Android 8, for newer Android versions it must be WM 23 or 24

[infosonline.net]
Re: WM22: Android - update user app without Playstore
January 08, 2020 06:26PM
Hello everyone

Here is the code that works for the question listed here:


PROCEDURE Auto_update()

dtVerzija_nova is DateTime
dtVerzija_stara is DateTime

nKonekcijaID is int
nKonekcijaID = FTPConnect("ftpserver","ftpuser","ftppasw",21)
IF nKonekcijaID <> -1 THEN
IF FTPFileExist(nKonekcijaID,"/APK/Infos.apk") THEN
    dtVerzija_nova = FTPDateTime(nKonekcijaID,"/APK/Infos.apk")
    dtVerzija_stara = fDateTime(fExeDir()+"\Infos.apk")
    IF dtVerzija_nova <> dtVerzija_stara THEN
         IF FTPGet(nKonekcijaID,"/APK/Infos.apk",fExeDir()) THEN
             IF ShellExecute(fExeDir()+"\Infos.apk") THEN
                  ToastDisplay("Instalirana je najnovija verzija aplikacije")
             END
         END
    END
END
FTPDisconnect(nKonekcijaID)
ELSE
//Error()
END



REMARK:

WM 22 - This code works until Android 8, for newer Android versions it must be WM 23 or 24

[infosonline.net]



Edited 2 time(s). Last edit at 01/23/2020 03:23PM by infos.
Re: WM22: Android - update user app without Playstore
January 09, 2020 11:09AM
Hi infos,
thanks for the reply.
I tried your code, but at the time it tries to install the new version, it says "There was a problem while parsing the package.".
I tried changing the destination folder from fExeDir() to SysDirExternalStorage(1,sseAppDownload), and this time it says "App not installed. The package appears to be corrupt."
Am I missing something?

P.S.: I'm using WM 23 and the device runs on Android 7

EDIT: I've found that the new version of the apk must have the value android:versionCode in the manifest greater than the one on the device, now it updates properly.
Just one thing: how do i automatically restart the app after it's updated?
TIA



Edited 1 time(s). Last edit at 01/09/2020 02:47PM by Wilaroth.
Re: WM22: Android - update user app without Playstore
January 09, 2020 04:12PM
Hello Wil

1. Yes, as I said the problem is in the WM version and the Android version.

2. Try RunExe or message the user to restart the application

[infosonline.net]
Re: WM22: Android - update user app without Playstore
January 10, 2020 11:33AM
Hi infos,
tried with RunExe, but without success. I think that the message is the only possible way, sadly.
Re: WM22: Android - update user app without Playstore
January 21, 2020 05:41PM
Hi,
actually using WM23.
With the method described by infos, I can get it to work on devices with version 7.1 or lower.
However, when i try to do the same on a device with 8.0 or greater, at the ShellExecute function it doesn't open the window for upgrading / installing the apk.
How can I fix this?
Bob Stratton
Re: WM22: Android - update user app without Playstore
January 22, 2020 02:45PM
Hi,

You could set it up as a private app in the playstore if you only want certain people to be able to use it.

[support.google.com]
Re: WM22: Android - update user app without Playstore
January 22, 2020 08:01PM
Wilaroth, I basicly do the same as you and it works on Android 5 and higher, including Android 8.

- WM23
- Android SDK 25
- I added both INSTALL_PACKAGES and REQUEST_INSTALL_PACKAGES to the APK generation script (using the wizard in WM)
- I download the file and save it in fCurrentDir() + ["/"] + ProjectInfo(piConfiguration)
- And finally do a ShellExecute with that file

Note: You need to rebuild every APK before testing/performing the install. Only then it gets a new internal "Generation number", which is visible in the advanced options of the WM wizard. That was my mistake with a lot of tests. I just tested the various ShellExecute() options with different paths and so on, but with the same APK and thus "generation number" over and over again. This will result in a "Parsing error" in log (logcat).

Arie
Re: WM22: Android - update user app without Playstore
January 23, 2020 08:33AM
Hi Ariel and Bob,
thanks for the replies.
What I was missing was indeed the REQUEST_INSTALL_PACKAGES permission to be inserted directly in the manifest.
Couldn't find this one in the wizard, so i've just added a child node called uses-permission, and with the attribute

android:name android.permission.REQUEST_INSTALL_PACKAGES
Re: WM22: Android - update user app without Playstore
January 23, 2020 03:31PM
Wilaroth

You are working on WM22, does this mean that with this add-on REQUEST_INSTALL_PACKAGES the thing works on newer versions of Android like Android 8?

[infosonline.net]
Re: WM22: Android - update user app without Playstore
January 24, 2020 12:23PM
FYI

ShellExecute seems to start the installation proces as a child-proces of your current app. Which causes some kind of confflict. It does install the update, but afterwards there is no option to start the app. As we know from a fresh/new install.

I also tries ExeRun wirth no luck, does not start the installation in the first place.

But the below piece of code seems to do the trick. Instead of a child-proces is launches a new activity/process. And then at the end the user is given the option to start your app.

It is also important that your app can exit friendly from that point, as the installer tries to kill it.(I'm not sure if a "Do you really want to exit..." dialog will block that)

Create a global JAVA procedure with the following code and then just call ApkInstall(your_apkfile) from your Windev code

import java.io.File;
import android.content.Intent;
import android.net.Uri;
import android.content.Context;

public static void ApkInstall(String sAPK){

	Intent i = new Intent();
	i.setAction(android.content.Intent.ACTION_INSTALL_PACKAGE);
	i.setDataAndType(Uri.fromFile(new File(sCheminAPK)), "application/vnd.android.package-archive");
	i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	getActiviteEnCours().startActivity(i); 
	
}

Arie
Re: WM22: Android - update user app without Playstore
January 27, 2020 08:25AM
@infos yes, exactly, with that integration it begins to work even on android 8 and 8.1, not sure of the versions above though

@Arie thanks for the tip, i'll surely try that
Re: WM22: Android - update user app without Playstore
January 27, 2020 03:49PM
ArieM Wrote:
-------------------------------------------------------
> FYI
>
> ShellExecute seems to start the installation
> proces as a child-proces of your current app.
> Which causes some kind of confflict. It does
> install the update, but afterwards there is no
> option to start the app. As we know from a
> fresh/new install.
>
> I also tries ExeRun wirth no luck, does not start
> the installation in the first place.
>
> But the below piece of code seems to do the trick.
> Instead of a child-proces is launches a new
> activity/process. And then at the end the user is
> given the option to start your app.
>
> It is also important that your app can exit
> friendly from that point, as the installer tries
> to kill it.(I'm not sure if a "Do you really want
> to exit..." dialog will block that)
>
> Create a global JAVA procedure with the following
> code and then just call ApkInstall(your_apkfile)
> from your Windev code
>
>
> import java.io.File;
> import android.content.Intent;
> import android.net.Uri;
> import android.content.Context;
> 
> public static void ApkInstall(String sAPK){
> 
> Intent i = new Intent();
> i.setAction(android.content.Intent.ACTION_INSTALL_PACKAGE);
> i.setDataAndType(Uri.fromFile(new
> w File(sCheminAPK)),
> "application/vnd.android.package-archive");
> i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
> getActiviteEnCours().startActivity(i);
> 
> }
>



Arie


Does this java code not work?
When apk is generated java code error occurs

[infosonline.net]
Re: WM22: Android - update user app without Playstore
January 27, 2020 03:56PM
Wilaroth

Not a problem in REQUEST_INSTALL_PACKAGES

Action FTPGet needs to download apk to another folder eg Download and not to fExeDir () and then everything will work fine, I tested

[infosonline.net]
Re: WM22: Android - update user app without Playstore
January 27, 2020 07:46PM
I'm sorry there's a little typo. Originally it's a French piece of code I found somewhere. I used it that way but translated it for this forum without testing first .

Should be this

import java.io.File;
import android.content.Intent;
import android.net.Uri;
import android.content.Context;

public static void APkInstall(String sAPK){

	Intent i = new Intent();
	i.setAction(android.content.Intent.ACTION_INSTALL_PACKAGE);
	i.setDataAndType(Uri.fromFile(new File(sAPK)), "application/vnd.android.package-archive");
	i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	getActiviteEnCours().startActivity(i); 
	
}

Arie
Re: WM22: Android - update user app without Playstore
January 31, 2020 02:59PM
Arie

Unfortunately, this code does not produce a good result either

It displays the same message as with my code

I don't know if it's okay with you?

[infosonline.net]
Re: WM22: Android - update user app without Playstore
February 03, 2020 09:31AM
No problem here. Can you copy/paste the error?

Arie
Re: WM22: Android - update user app without Playstore
February 03, 2020 01:45PM
Arie

Error

There was a problem parsing the package

[infosonline.net]
Re: WM22: Android - update user app without Playstore
February 04, 2020 01:32PM
Then it's getting more difficult I'm afraid.

I had one situation where the Android versoin on the tablet was too old (4.0 where I had set 4.4. as the minimum somewhere in the APK-generation wizard)

Maybe you can use the Android log (logcat) to get more details about this error.
Google for ADB and Logcat, I don't have a step by step instruction for that

Arie
Re: WM22: Android - update user app without Playstore
July 08, 2020 10:29AM
Hi everyone,
I've managed to make it work on android 8 and below, with the combination of FTPGet and ShellExecute to start the update (while having REQUEST_INSTALL_PACKAGES in the manifest).
However, with Android 10 ShellExecute doesn't work anymore, as it returns the error "The document was not opened because no application is properly associated".
Is there a way to make it work?
TIA

P.S.: I'm using WM23
what I do (working on all version of android I tested):
1. TELL THE USERS TO AUTHORISE INSTALLS FROM ANOTHER SOURCE THAN PLAYSTORE <<< can't work without that
2. read ini file on server via httprequest
3. if new version, download it via httprequest
4. run it via shellexecute
5. endprogram

works like a charm
Re: WM22: Android - update user app without Playstore
July 11, 2020 08:57AM
Hello Argus

I tried something similar but it didn't work!

Do you have a code to share with us here

Thank you

[infosonline.net]
I am not in a legal position where I can offer my code here... Sorry.

When I was trying to do that, I used Fabrice's consulting help to do the initial setup, so if you are stuck, you can do the same.
Re: WM22: Android - update user app without Playstore
July 12, 2020 03:22PM
Greeting

a little funny answer but good

[infosonline.net]
I fail to see how a legal document/contract like a confidentiality agreement is funny in any way, shape or form, and I've never seen anybody laugh while reading one, so I'll let you laugh by yourself in this case
Re: WM22: Android - update user app without Playstore
July 13, 2020 04:51PM
Argus

We did not understand each other

I did not ask for your private information from your company

I asked the code in general, WLanguage or java or any other code are public right

but well, I respect your discretion

Best regards

[infosonline.net]



Edited 2 time(s). Last edit at 07/13/2020 04:55PM by infos.
Re: WM22: Android - update user app without Playstore
July 14, 2020 06:50AM
Hi Infos and Argus,

Maybe Info show your code first? Then maybe Argus could point out any code that need to be changed?

It would be great to get some working code to do this!

Cheers

Pete
Re: WM22: Android - update user app without Playstore
July 14, 2020 02:17PM
Hello Peter

I have already posted the code on this topic above above here
but not satisfactory

[infosonline.net]
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: