add my app to the “add shortcut” list to have a shortcut on homescreen

那年仲夏 提交于 2019-12-06 05:26:26

That functionality is already there by default, they just have to choose from the "Applications" list. You can't add directly to the main shortcuts list (it would get far too cluttered quickly), that's provisioned by the operating system and to my knowledge cannot be populated by a third party application.

Shortcuts had existed since API level 1, and can be used by 3rd party apps as well.

To add an activity to the shortcuts manu simply add this intent filter to your activity in your manifest:

    <intent-filter>
        <action android:name="android.intent.action.CREATE_SHORTCUT" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>

To make the activity plant a new icon with an intent on the home screen, do this before finishing:

Intent intent = new Intent();
Intent launchApp = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchApp);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "My shortcut");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, myIcon);
setResult(RESULT_OK, intent);

Change the launchApp intent to whatever you want launched when this is clicked.

See here: http://developer.android.com/reference/android/content/Intent.html#ACTION_CREATE_SHORTCUT

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!