add my app to the “add shortcut” list to have a sh

2019-05-22 20:31发布

As you know when you long press on the home screen, the phone shows up a list menu. You can add shortcuts, widgets, Folders, etc. I would like my app to be in the shortcut list.

How can I do that?

2条回答
冷血范
2楼-- · 2019-05-22 21:00

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.

查看更多
倾城 Initia
3楼-- · 2019-05-22 21:01

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

查看更多
登录 后发表回答