First you will need to add permission to your manifest.xml
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"> </uses-permission>
You will need to create an intention to view the web page. Something like...
Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setData(Uri.parse("http://www.blablaba.com"));
You can verify this by creating a small test application and running startActivity (i); This should open the browser. After you confirm the correctness of the above intention, proceed to the next step.
Now you will need to set a 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)
;
It is also possible that some home screens do not accept this, but most of them. So enjoy it.
EDIT: The icon can be set to a shortcut using:
installer.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(mContext, R.drawable.icon));
Mike dg Apr 15 2018-11-11T00: 00Z
source share