How to force creation of Website Shortcut on homescreen of an Android device from PWA way

Viewed 120

I'm looking for a way, from a private AppStore to create a shortcut on the homescreen on Android / IOS.

In other words (and example): In my private AppStore, I would like to add a Google Card (which is basically an URL to Google) and a button "Install". When my end-user, clicks on "install", I would like A shortcut to Google to be created on the User Homescreen.

Is there a way to do this?

1 Answers

If I correctly understand your question you want to have something like a launcher icon to open a url and that shortcut should be created dynamically using your other app which you apparently call your AppStore

I think the following solution should help you

First we proceed by creating manifest permissions

<uses-permission
            android:name="com.android.launcher.permission.INSTALL_SHORTCUT">
</uses-permission>

Then you can build an intent to the webpage you want, in this case, Google

Intent i = new Intent();
i.setAction(Intent.ACTION_VIEW);
i.setData(Uri.parse("https://www.google.com"));

And finally the most important step that is creating your shortcut

Intent installer = new Intent();
    installer.putExtra("android.intent.extra.shortcut.INTENT", i);
    installer.putExtra("android.intent.extra.shortcut.NAME", "THE NAME OF SHORTCUT TO BE SHOWN");
    installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", I THINK this is a bitmap); //can also be ignored too
    installer.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(installer)

Depending on the launcher that your device uses, it may or may not be possible but will definitely work on Android launchers

Related