Reputation: 1397
In Nova Launcher (and many other custom ones) there is a Gesture configuration where you can assign various actions to a gesture. Among those actions there is a Shortcuts tab. How can I add a shortcut in my own app that can be recognized by the launcher? (I suppose it's something that I have to add to the Manifest and set an Intent to it)
EDIT: Here's an image to point out those actions.
Upvotes: 3
Views: 1469
Reputation: 10097
These are very poorly documented and unfortunately were previously called "Launcher shortcuts" and now have been left nameless. In addition to being in Nova's gesture menus and similar, they also show next to widgets in the widget drawer. I think of the as "widget shortcuts".
The official documentation seems to be limited to a demo in ApiDemos: https://android.googlesource.com/platform/development/+/master/samples/ApiDemos/src/com/example/android/apis/app/LauncherShortcuts.java
The idea is that in your manifest you handle android.intent.action.CREATE_SHORTCUT
and return a result to the launcher with the label, icon and target intent. Then the launcher can make it into an icon on the desktop or just use the intent for a gesture or whatever.
In your AndroidManifest.xml
<activity android:name=".CreateShortcut">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Then when the user picks your shortcut the launcher does a startActivityForResult
of that activity, you can either finish
right away with a result, or you can display a UI to the user to let them configure the shortcut.
Either way, when ready return the info to the launcher:
Intent result = new Intent();
result.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);
result.putExtra(Intent.EXTRA_SHORTCUT_NAME, targetLabel);
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(
this, R.drawable.ic_launcher_shortcut);
result.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
setResult(RESULT_OK, result);
finish();
Upvotes: 8
Reputation: 1446
Are you referring to App Shortcuts? The Android developer guide has quite a thorough tutorial on them.
Upvotes: 0