How to install an .apk or .ipa file stored on my device?

152 views
Skip to first unread message

Mark Bolduc

unread,
Jul 22, 2020, 10:40:04 AM7/22/20
to CodenameOne Discussions
If you are experiencing an issue please mention the full platform your issue applies to:
IDE: NetBeans/Eclipse/IDEA Netbeans 12 JDK 9
Desktop OS Windows 10 Pro
Simulator latest
Device IOS & Android

Your Codenameone build app downloads and installs apps from the codenameone build server.

I have downloaded the .ipa and .apk installers from the build server and stored them in a downloads directory for one of my apps.
I want to from the app execute the installation same as the codenameone build app does or store the installers in a folder that can be reached from the desktop and manually run.

Can you please share with me how to accomplish this?

Best Regards

Stay Safe!

Dave Dyer

unread,
Jul 22, 2020, 1:27:27 PM7/22/20
to CodenameOne Discussions
It sound like you've stored them on the downloads directory of your PC.  You need to download them
directly onto your mobile devices, which ought to trigger the installation.

Shai Almog

unread,
Jul 22, 2020, 10:53:59 PM7/22/20
to CodenameOne Discussions
We don't download the files. We launch an external download process using execute(url). We also don't point at the IPA but rather at a manifest.
Regardless Apple won't approve your app if you do that. Which is why Codename One Build only works as a web app for iOS which IMO is pretty stupid.

Mark Bolduc

unread,
Jul 23, 2020, 7:06:15 AM7/23/20
to CodenameOne Discussions
Thanks, I have downloaded the .apk file to the mobile device and did call:

Display.getInstance().execute(ApplicationBinariesDownloadPath + fileName, e -> {
                System.out.println("saveAndInstallA3MobileApp Complete");
            });

Can you provide the code syntax to install the .apk or .ipa file that is stored on the mobile device?

BTW: I have no intention of publishing my apps at this stage.

Also, Google made life a lot more complex by requiring a privacy policy be hosted if you access things like camera etc.

Mark Bolduc

unread,
Jul 23, 2020, 8:09:37 AM7/23/20
to CodenameOne Discussions
You mentioned pointing the execute process to a manifest, how does this work?

Curious, when an .apk file exists in the devices download directory, from a file browser, we can click on it and it installs.

Shai Almog

unread,
Jul 24, 2020, 12:59:57 AM7/24/20
to CodenameOne Discussions
As I said we don't download. We call the URL on the web and the native download sequence performs the actual download process. The execute method accepts an https URL in our servers.

Look at the result of our iOS builds in the browser and inspect the code. It's an HTML page that points at an XML file that's the manifest.

Mark Bolduc

unread,
Jul 24, 2020, 9:08:02 AM7/24/20
to CodenameOne Discussions
There has to be a way to trigger an install from the .apk and .ipa files within codenameone.

Using Display.getInstance().execute(???) what process or browser or app can I execute and have it point to the .apk or .ipa file?

The devices download the app and store them in the downloads directory, If I browse that directory I can tap the .apk or .iap file and it will install.

I want to do this programmatically.

How can my app save a file on the devices downloads directory?

Regards.

Mark Bolduc

unread,
Jul 24, 2020, 9:45:31 AM7/24/20
to CodenameOne Discussions
Alternatively I found this for Android:

public String getDownloadPath() {
    return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + File.separator + "myfolder";
}

How do I programmatically access (for read & write) the downloads directory?

Shai Almog

unread,
Jul 25, 2020, 1:42:07 AM7/25/20
to CodenameOne Discussions
You can't do that on iOS. Codename One build which just uses a web download URL was rejected by appstore review so iOS won't let you do that at all.
On Android you can do that but it would require a lot of permissions you honestly don't want to ask for. You're better off letting the default app walk the user through those things.

Mark Bolduc

unread,
Jul 25, 2020, 8:03:44 AM7/25/20
to CodenameOne Discussions
Thanks, perhaps I can make this request simpler. (I don't have any near future requirements of publishing my apps with google or apple)
So with all due respect to Apple, I am not interested in what apple will accept.

I have it stuck in my head that an .apk & .ipa file is an installer and executing it (from what ever means is needed) will be verbose and open up dialogs to ask user for needed permissions to access photos, caners, audio etc.

I believe if I can save an .apk (Android) file in the (android native method: "ExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)"), I can then open a browser pointed to the downloads directory and execute the installer for that app. This should work for .ipa & .apk files.

Or just dialog the user with instructions.

So in codenameone, how do I access the public downloads directory for read & write?
My App already downloads the .apk & .iap files and saves it in the "FileSystemStorage.getInstance().getAppHomePath() + "A3-TECH/A3-TechAppDownloads/"
So I don't see how to access the public downloads directory.

Best Regards.

Mark Bolduc

unread,
Jul 25, 2020, 8:21:42 AM7/25/20
to CodenameOne Discussions
Using codenameone build app, I can download the .apk file to the public downloads directory.
Then using file manager can open the downloads directory, tap the .apk file and install it.

Please see attached pic "Screenshot_20200725-081618_File Manager.jpg"

I want to replicate this.

Please advise

Regards.
Screenshot_20200725-081618_File Manager.jpg

Dave Dyer

unread,
Jul 25, 2020, 4:40:41 PM7/25/20
to CodenameOne Discussions

Android is easy.  My understanding of IOS is that you can only do ad-hoc installations
on devices that are explicitly ennumerated in the provisioning of the app, and there are
limits on how many of those there can be.  Anything for general distribution has to
be accepted by (and signed by) apple.

Shai Almog

unread,
Jul 25, 2020, 10:10:27 PM7/25/20
to CodenameOne Discussions
We literally use CN.execute(url_of_app). Where the URL is an HTTP URL that contains the application.
No magic, no native code.

The one thing you might have gotten wrong is the HTTP hosting. You need to make sure your server is HTTPS and that it has the right mime types for the links.

But again, you'll only be able to do this on Android. On iOS you can't even distribute an app without going through the store.

Mark Bolduc

unread,
Jul 26, 2020, 7:26:34 AM7/26/20
to CodenameOne Discussions
Agreed regarding "explicitly ennumerated in the provisioning of the app" I do this. These apps will not be published VIA Apple for our current business model.

Please advise the classes needed to save a file in the android public downloads directory.

Regards.

Dave Dyer

unread,
Jul 26, 2020, 1:44:05 PM7/26/20
to CodenameOne Discussions

I don't know if you can install an IOS build that is stored somewhere on the device, but I have
succeeded in installing  a debug build stored on my web site, by dissecting and modifying
the HTML that accompanies the build in the codename1 dashboard.  Sorry, I don't have the
details at hand, it was something of a pain to do and I haven't maintained the practice.

Shai Almog

unread,
Jul 26, 2020, 10:15:11 PM7/26/20
to CodenameOne Discussions
It's a bit more complex than that. In iOS you can't physically install apps without a certificate. You have two options here:

- Development certificate - works on 100 devices which you have to add personally to a provisioning profile. Or on 1000 devices via itunes
- Enterprise certificate - works on devices within your organization. This means the device needs to be a part of your org. If it belongs to a different org this won't work.
This is something some developers "abused" to create 3rd party appstores which Apple shut down by revoking the certificate for ToS violation.

We don't have any such classes for the public download directory. Codename One build just uses execute(URL) and launches your native web browser on every OS. We don't download any file.

FYI AFAIK you are allowed to link to itunes/play listings and if you open the browser to the listing and let the user install the app through there that's 100% "legal" and doesn't require any complexity. This will let you install dependencies easily on all OSs.

Mark Bolduc

unread,
Jul 27, 2020, 8:57:20 AM7/27/20
to CodenameOne Discussions
Ok, I would like to focus on Android build only.

In another Post (titled lunch browser) it was suggested to use Display.execute() to open native browser.

Can you please complete the code to point to and execute the native browser with argument to open .apk?
Display.getInstance().execute(????); where ???? is native browser and 1 argument i assume would be a URI
Please fill in the ????

Regards

Shai Almog

unread,
Jul 27, 2020, 10:43:23 PM7/27/20
to CodenameOne Discussions
Execute opens a URI using the platform native system. We didn't use it for a locally downloaded file only for a web link so in this case it literally opens the browser and lets it deal with the permissions and related complexities.
If you want to do the download yourself this is something we didn't do in Codename One Build. I'm guessing the native Android code you have should work within a native interface. You might need to add some permissions and declare them in the XML using the xpermissions build hint.

Mark Bolduc

unread,
Jul 28, 2020, 9:16:56 AM7/28/20
to CodenameOne Discussions
I want to open a browser with an .apk argument from Display.getInstance().execute([default browser])
I don't have a clue how to execute the default browser, what text do I substitute "[default browser]" with?

Can I open the default browser in my app?
If so can I pass the browser a local .apk file for it to open?
Will this work?

Regards;

Mark Bolduc

unread,
Jul 28, 2020, 1:04:43 PM7/28/20
to CodenameOne Discussions
Ok, I have successfully stored my .apk file in the  public /storage/emulated/0/Download/ directory, I can then open a FileManager, tap downloads, Tam my app and it installs correctly.

So the question is how can I envoke this "File Manager" app installed on my device.
I can't find its location.

Once I have its location, can I use "Display.getInstance().execute("file:///[path to file manager app]")" to open the FileManager app?

Thoughts?

Regards

Shai Almog

unread,
Jul 28, 2020, 10:34:58 PM7/28/20
to CodenameOne Discussions
If you provide a standard https URL the default browser will launch. As a sidenote you can provide URLs such as "fb:" to launch facebook and other apps.
So standard URLs use Chrome/Safari or whatever you have defined.

file:/// won't work. That's not an Android URI. You need to look for the intent you want. Alternatively you can use a native interface for this which might be simpler since you're doing something that's very platform specific.

Mark Bolduc

unread,
Jul 29, 2020, 7:37:18 AM7/29/20
to CodenameOne Discussions
Thanks.

Mark Bolduc

unread,
Jul 29, 2020, 4:19:44 PM7/29/20
to CodenameOne Discussions
Can you please advise how I can open an app that is installed on my device i assume using Display.getInstance().execute(path to app) or is there another preferred method to do this?

Is there documentation regarding this?

Shai Almog

unread,
Jul 29, 2020, 10:04:27 PM7/29/20
to CodenameOne Discussions
There's no path to app. Apps work in isolation in devices. So one app can't see the files of another app. On Android they have different user IDs for each app to keep them completely isolated in the kernel level.
Something like this should (probably) work:

execute("intent:#Intent;scheme=customapp;package=com.my_package.name;end");

Where you need to set "com.my_package.name" to the package of the app you want to launch.

Dave Dyer

unread,
Jul 30, 2020, 12:51:36 AM7/30/20
to CodenameOne Discussions
why are you so fixated on getting the app to auto-install?  It suggests you are
trying to accomplish something underhanded, when there are simple and
customary ways to install apps.



s. 

Mark Bolduc

unread,
Jul 30, 2020, 10:08:03 AM7/30/20
to CodenameOne Discussions
Good Question Dave,


On the contrary, we do not publish a web site, we are developing for a closed network of Automotive Shop Owners.
I am emulating how our java Swing application administration management suite works and operates on a  completely private network.


Our Shop Apps are above board and operate in a closed local network.
We require access to Camera, Local Storage (persist properties etc.) Phone dialing.

It will be required in the future that a Customer (Auto Shops Customer) would have a mobile app that would require internet access to a published Server, however that is planned for Q1 of 2021.

Not being able to auto install (user interactive of course) is not a show stopper, just want to simplify the application administration for our auto shop users.

Hope this puts your mind at ease regarding the integrity of our apps.

Thoughts?

Regards.

Dave Dyer

unread,
Jul 30, 2020, 2:46:53 PM7/30/20
to CodenameOne Discussions
If you simply put a link to the APK somewhere in your web site workflow, when your
customers click on it they're fall into the "install" cycle.  OTOH, the advantage
of being in the app store, even if you don't intend non-customers to install it,
is that updates are installed automatically.   I think it's possible to have
private label apps in the app store that than only be installed from an
external link, and won't be found in searches.


Shai Almog

unread,
Jul 30, 2020, 10:52:17 PM7/30/20
to CodenameOne Discussions
OK I think I got it. I think the best thing for you to do is to add additional apps.
For mobile you should think of this as multiple apps not as a single app with modules. This is a bit of a pain as you need to upload and manage on the store a network of apps but this will significantly simplify the process of installing/administering these apps and will work 100% on iOS, Android etc.

Think of it like the relationship between the Facebook app and Messenger. They can each launch each other and send you to the install page of one another. If you do this you don't need any permissions whatsoever. Just execute the link to the app on the respective store.

Dave Dyer

unread,
Jul 31, 2020, 1:00:08 PM7/31/20
to CodenameOne Discussions
If you've got a dozen little apps that act as modules and cooperate with each other, I would think
long and hard about just bundling them into a single app.  There are sooooo many ways a gaggle
of apps can become out of sync and fail to work together, and coordinating changes among them
is a pain.  Not to mention that you have to keep building and distributing them all.

Mark Bolduc

unread,
Jul 31, 2020, 3:43:09 PM7/31/20
to CodenameOne Discussions
Thanks Guys.

I think to put this issue to bed, I would like to get this working:


Display.getInstance().execute("intent:#Intent;scheme=customapp;package=com.diamond.apps.filemanager;end");
However it generates the error attached "AndroidGalaxy5S2ExecuteIntentErrors_1.jpg"

See pic "AndroidGalaxy5S2com.diamond.apps.filemanager_2.jpg" for class path from Filemanager app.

Thoughts?

Regards
AndroidGalaxy5S2ExecuteIntentErrors_1.jpg
AndroidGalaxy5S2com.diamond.apps.filemanager_2.jpg

Shai Almog

unread,
Jul 31, 2020, 10:53:29 PM7/31/20
to CodenameOne Discussions
I don't see anything in the logs here can you place them as text somewhere?

Mark Bolduc

unread,
Aug 1, 2020, 9:40:57 AM8/1/20
to CodenameOne Discussions
Yes,

See attached "AndroidGalaxy5S2com.diamond.apps.filemanager_1ErrorLog.txt"

Additionally, can you provide the codenameone build app string ?
Display.getInstance().execute("intent:#Intent;scheme=customapp;package=[path to codenameone build app];end"); (Android Only)
AndroidGalaxy5S2com.diamond.apps.filemanager_1ErrorLog.txt

Shai Almog

unread,
Aug 1, 2020, 11:05:28 PM8/1/20
to CodenameOne Discussions
It looks that it works but the file manager in question doesn't seem to support that for some reason. Can you open other apps with this intent?

Mark Bolduc

unread,
Aug 2, 2020, 7:08:54 AM8/2/20
to CodenameOne Discussions
I don't know.

can you provide the codenameone build app string ?Display.getInstance().execute("intent:#Intent;scheme=customapp;package=[path to codenameone build app];end"); (Android Only)

Shai Almog

unread,
Aug 2, 2020, 11:29:44 PM8/2/20
to CodenameOne Discussions
It should launch for "com.codename1.build.app" although I haven't tried that.

Mark Bolduc

unread,
Aug 3, 2020, 7:35:39 AM8/3/20
to CodenameOne Discussions
Seems like the syntax of this call is suspicious.
Display.getInstance().execute("intent:#Intent;scheme=customapp;package=com.codename1.build.app;end");

Getting

Thoughts?

regards

"08-03 07:27:13.129 25211 25240 D AstcTechMobileApp: [invokeAndBlock1] 0:0:12,923 - Exception: android.content.ActivityNotFoundException - No Activity found to handle Intent { act=android.intent.action.VIEW dat=customapp: pkg=com.codename1.build.app }
08-03 07:27:13.129 25211 25240 W System.err: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=customapp: pkg=com.codename1.build.app }

Shai Almog

unread,
Aug 3, 2020, 10:50:31 PM8/3/20
to CodenameOne Discussions
You also need to change "customapp" to CodenameOneBuildApp. Sorry missed that.

Mark Bolduc

unread,
Aug 5, 2020, 7:38:39 AM8/5/20
to CodenameOne Discussions
Thanks,

Ran with "" and got error:
D AstcTechMobileApp: [invokeAndBlock2] 0:2:20,93 - Exception: android.content.ActivityNotFoundException - No Activity found to handle Intent { act=android.intent.action.VIEW dat=CodenameOneBuildApp: pkg=com.codename1.build.app }
08-05 07:27:01.660 21429 21610 W System.err: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=CodenameOneBuildApp: pkg=com.codename1.build.app }

Please see attached log. "Codename1_1Log.txt"

Please see screen shot of execute argument in attached pic "AndroidGalaxy5S2ExecuteIntentErrors_2.jpg"

Thoughts?

Regards
Codename1_1Log.txt
AndroidGalaxy5S2ExecuteIntentErrors_2.jpg

Shai Almog

unread,
Aug 5, 2020, 9:53:30 PM8/5/20
to CodenameOne Discussions
Sorry got this wrong again, the right scheme for the builder app is "cn1bldapp".

Mark Bolduc

unread,
Aug 6, 2020, 9:14:08 AM8/6/20
to CodenameOne Discussions
Interesting, running this:

Display.getInstance().execute("intent:#Intent;scheme=cn1bldapp;package=com.codename1.build.app;end");

Opened the expected app, however it appears to have displaced my app instance.
(In that when I tap the ||| on the tablet to show all running apps, I only;y see my app, yet ith is actually the build app.)
See attached pic. "Running Codename1Build App Showing My App Icon_1.jpg" 
minimizing the build app and then tapping on my app icon, reopens the build app.

From a users perspective, My app is now linked to the build app in memory. until i kill the app and all is normal.

Curious, Is this the expected behavior?

I was expecting to have spawned the codename1 build app, where my app would be minimized.

If not, is there a way to spawn this so my app is in background and reachable or is this illegal in the Android world?

Thoughts?

Rgards
Running Codename1Build App Showing My App Icon_1.jpg
Running Codename1Build App Showing My App Icon_2.jpg

Shai Almog

unread,
Aug 6, 2020, 10:55:21 PM8/6/20
to CodenameOne Discussions
That's Android Intents. You can use the back button to return to the previous app

Mark Bolduc

unread,
Aug 7, 2020, 9:00:09 AM8/7/20
to CodenameOne Discussions
Touch back button (Running Codename1Build App Showing My App Icon_3.jpg)
brings me to the Android main apps screen (Running Codename1Build App Showing My App Icon_4.jpg),
Tap on "|||" to show previous running apps shows(Running Codename1Build App Showing My App Icon_5.jpg)
Note: The (Running Codename1Build App Showing My App Icon_5.jpg) pic you will see the Codename1 Build app with My Apps Icon top middle.
Now, from the main apps screen, I tap on my apps icon (Running Codename1Build App Showing My App Icon_6.jpg)
And the Codename1 Build app opens.

I don't want to beet a dead horse, however would be interested in your thoughts.

Regards.
Running Codename1Build App Showing My App Icon_3.jpg
Running Codename1Build App Showing My App Icon_4.jpg
Running Codename1Build App Showing My App Icon_5.jpg
Running Codename1Build App Showing My App Icon_6.jpg

Shai Almog

unread,
Aug 8, 2020, 12:20:13 AM8/8/20
to CodenameOne Discussions
I'm sorry, I don't use activities all that much and don't really remember all the nuances and oddities of the Android activity stack. It's a pain for sure.
I think the reason back misbehaves is because we explicitly programmed back to exit the app in Codename One apps by default. This is easily fixed in a Codename One app but obviously you can't do that to Codename One build.
Just use the URL association instructions I showed to you previously and set the back command behavior to go back to the previous app.

Mark Bolduc

unread,
Aug 8, 2020, 7:49:51 AM8/8/20
to CodenameOne Discussions
Thanks, Stay Safe!
Reply all
Reply to author
Forward
0 new messages