質問

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