JamieZ
JamieZ

Reputation: 41

How to create shortcuts from other android apps

I am looking for a way to create shortcuts from other apps. Like launchs can query the apps that allow to create shortcuts and create them save them in thier program.

My API version is between M(21) to N7.1(25).

Even just a link or name of API it's fine. I just couldn't find it at all. All I found is about the new shortcut in android N.

Thx for ur time.

Upvotes: 1

Views: 340

Answers (1)

JamieZ
JamieZ

Reputation: 41

I found the way to do it. Since i don't see much info for this. I hope my share can help whoever is also looking for the answer.

So there will be 3 steps:

  1. Get apps that can create shortcuts
  2. Send Intent to the app that you want to create shortcut from
  3. Get shortcut data in Activity.onActivityResult

1. Since I just need to create shortcuts from certain apps. I skipped step one. But I guess using queryIntentActivities(...) or some other functions in PackageManager can get you the list.

Intent intent = new Intent("android.intent.action.CREATE_SHORTCUT");
PackageManager.queryIntentActitvies(intent,0);

2. Send intent to the app to create a shortcut.

Intent intent = new Intent("android.intent.action.CREATE_SHORTCUT");
intent.setComponent(...);
startActivityForResult(intent, requestCode);

3. Get data of shortcut:

  1. Shortcut intent

Intent shortcutIntent = activityResultIntent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);

  1. Shortcut name

String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);

  1. Shortcut icon

Bitmap shortcutIcon = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);

Upvotes: 2

Related Questions