Recent

Author Topic: Automatic update app from own server without G play  (Read 2124 times)

schumi

  • New Member
  • *
  • Posts: 40
Automatic update app from own server without G play
« on: February 09, 2021, 05:07:54 pm »
Hi,
some rugged device have't google play, it is possible auto update an app create with lamw?
-download new apk from a server
-install apk
I'am looking for an example with LAMW.

thanks

rsu333

  • Full Member
  • ***
  • Posts: 110
Re: Automatic update app from own server without G play
« Reply #1 on: February 10, 2021, 01:32:20 pm »
Without g play you can work. Your post not view  problem.

schumi

  • New Member
  • *
  • Posts: 40
Re: Automatic update app from own server without G play
« Reply #2 on: February 15, 2021, 03:04:38 pm »
Hi,
I don't want to report an error,  I'am looking for some examples Lazarus/FP/LAMW

thanks

Manlio

  • Full Member
  • ***
  • Posts: 162
  • Pascal dev
Re: Automatic update app from own server without G play
« Reply #3 on: February 21, 2021, 05:34:44 pm »
Here is how I do it:

1. Make sure you build your apps using the same package ID (com.example.myapp) and increasing version numbers. (That's the numeric version "code" in the LAMW Android Project Options form, and android:versionCode in the app's manifest.

2. Build the app and let people download the APK it from your website.

3. When uploading a new version on the web site, also update the web page, or your web server's database, with the latest version number of your app.

4. In your app, include a function that calls a particular page on your site, and retrieve the latest version available.

5. If your app detects that a new version is available on the website, inform the user, and give them a button or something that opens the download page with the default browser.

6. With a couple of clicks, therefore, your users will learn that a new version is available and will be taken to the download page. With one more click they can download the latest APK, and install it on top of the current version.

7. If you try to install a new version of the app as described above, if the android:versionCode of the new app is more recent than the one already installed, the process will go smoothly. Android will also tell you that the installation will update the app without altering the existing app data.

This is how I do it for a couple of apps of mine, and it's a private working group, so I can't show you, but I can tell you that it works.
manlio mazzon gmail

rsu333

  • Full Member
  • ***
  • Posts: 110
Re: Automatic update app from own server without G play
« Reply #4 on: February 22, 2021, 07:40:16 am »
This nice informative article  by malio , even useful for beginners

schumi

  • New Member
  • *
  • Posts: 40
Re: Automatic update app from own server without G play
« Reply #5 on: February 24, 2021, 06:00:19 pm »
hi,
I tried with this code for APK install, but app crash.
what i do wrong?

Code: Pascal  [Select][+][-]
  1. sFilePath := self.GetEnvironmentDirectoryPath(DirDownloads)+ '/' + 'file_name.apk' ;
  2.  
  3. if FileExists(sFilePath) then begin
  4.   jIntentManager1.SetAction('android.intent.action.VIEW');
  5.   jIntentManager1.SetFlag(ifActivityNewTask);
  6.   jIntentManager1.SetDataAndType('file:///'+self.GetEnvironmentDirectoryPath(dirDownloads)+'/file_name.apk','application/vnd.android.package-archive');
  7.   jIntentManager1.StartActivity();     <-- crash here
  8. end ;
  9.  

Manlio

  • Full Member
  • ***
  • Posts: 162
  • Pascal dev
Re: Automatic update app from own server without G play
« Reply #6 on: February 28, 2021, 12:59:33 pm »
hi,
I tried with this code for APK install, but app crash.
what i do wrong?

One reason could be Android (or some anti-virus app) protecting the device from secret installations.

Also keep in mind that these things often change from one Android version to another. (Older versions may be more permissive, newer versions tend to be more strict and careful with security issues).


For this reason I personally don't even try to install a new version of the app programmatically. I just tell the users about it, and make it easy to download it. Afterwards it's up to the user to click to proceed with the installation, when prompted by Android. In that way everything happens in the open, according to Android's own workflow.
manlio mazzon gmail

schumi

  • New Member
  • *
  • Posts: 40
Re: Automatic update app from own server without G play
« Reply #7 on: March 03, 2021, 09:44:12 am »
hi,
 I try with StartDefaultActivityForFile, app don't crash but don't install apk,
in other forum I have read about PackageManager for install apk
I would try to write a new function, here code I found

Code: Pascal  [Select][+][-]
  1. public void installPackage(Context context, String installSessionId, String packageName, InputStream apkStream) throws IOException {
  2.         PackageManager packageManger = context.getPackageManager();
  3.         android.content.pm.PackageInstaller packageInstaller =
  4.                 packageManger.getPackageInstaller();
  5.         PackageInstaller.SessionParams params = new PackageInstaller.SessionParams(
  6.                 PackageInstaller.SessionParams.MODE_FULL_INSTALL);
  7.         params.setAppPackageName(packageName);
  8.         android.content.pm.PackageInstaller.Session session = null;
  9.         try {
  10.             int sessionId = packageInstaller.createSession(params);
  11.             session = packageInstaller.openSession(sessionId);
  12.             OutputStream out = session.openWrite(installSessionId, 0, -1);
  13.             byte buffer[] = new byte[1024];
  14.             int length;
  15.             int count = 0;
  16.             while ((length = apkStream.read(buffer)) != -1) {
  17.                 out.write(buffer, 0, length);
  18.                 count += length;
  19.             }
  20.             session.fsync(out);
  21.             out.close();
  22.  
  23.             Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED);
  24.  
  25.             session.commit(PendingIntent.getBroadcast(context, sessionId,
  26.                     intent, PendingIntent.FLAG_UPDATE_CURRENT).getIntentSender());
  27.         } finally {
  28.             if (session != null) {
  29.                 session.close();
  30.             }
  31.         }
  32.     }
  33.  

 

TinyPortal © 2005-2018