Fork us on GitHub

Install on Home Screen

Progressive Web App icon on the device home screen
Install on Home Screen

Install on Home Screen

We talked about our support for Progressive Web Apps before. We added quite a few enhancements since that support was introduced and it’s a pretty powerful feature. Personally I consider it a killer feature, even if Google decides to ban your account you can still distribute your app.

One of the cool features is the seamlessness. Most of the functionality "just works". However, there are some cases where we need explicit hints due to the different behavior of desktop/mobile and web.

One such case is installation. PWA’s support an icon on the device home screen, but you need to explicitly ask the browser to install that icon. That’s unique to PWA’s and requires a new API to support that behavior. That’s why we introduced onCanInstallOnHomescreen, canInstallOnHomescreen() and promptInstallOnHomescreen() to help with that process. You can use them as:

onCanInstallOnHomescreen(()->{
    if (canInstallOnHomescreen()) {
        if (promptInstallOnHomescreen()) {
            // User accepted installation
        } else {
            // user rejected installation
        }
    }
});
This code expects import static com.codename1.ui.CN.*;

The code would prompt the user to install on the home screen in OS’s where this is appropriate. Notice that this will prompt the user once to install on the home screen so you don’t need additional guards against duplicate prompts.

Share this Post:

Posted by Shai Almog

Shai is the co-founder of Codename One. He's been a professional programmer for over 25 years. During that time he has worked with dozens of companies including Sun Microsystems.
For more follow Shai on Twitter & github.