문제

I've observed that in some cases, when yo install an app (for example shazam) a direct access it's automatically created in the home screen.

I want to export this behaviour to my developed apps.

Does someone know how it could be possible?

도움이 되었습니까?

해결책

Creating shortcut on the home screen through application on install is not possible. There is optional settings in Play Store App to auto create shortcut on install.

Alternatively,you can use below code to create shortcut in OnCreate method of MainActivity:

Require Manifest Permission.

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

Use below code to programmatically create shortcut.

Intent shortcutIntent = new Intent();
shortcutIntent.setClassName("<Your app package>", "Class Name");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Create shortcut itself

Intent addSCIntent = new Intent();
addSCIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addSCIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "<Shortcut Name>");
addSCIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_launcher);
addSCIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(addSCIntent);

다른 팁

I guess you mean adding a shortcut to the homescreen. This tutorial will help you.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top