Open In App

How to Add Capabilities to Shortcuts in Android 13?

Improve
Improve
Like Article
Like
Save
Share
Report

Shortcuts have been an integral part of Android Apps, almost every app we use has shortcuts that facilitate main activity opening with various time-savers, which turn out to be great time savers. Over the years this experience has greatly improved, and now we can add even more capabilities to our app. In this Geeks for Geeks article we will be discussing how to implement more capabilities in our Android apps which will help you get more users and help them to complete their work by saving more time. Without further ado, let’s get straight into the topic and learn how to add capabilities to your app, and bake a better UX. 

How does the key-fastener API work?

You can specify the kinds of actions users can take to open your app and proceed immediately to carry out a certain job using capabilities in shortcuts.xml. For instance, Google Assistant App Actions employ capabilities to give developers the ability to convert built-in intents (BII) from in-app features to built-in actions (GAAA), enabling users to activate and manage those features using spoken commands. A capability is made up of the name of the action and intent that is targeted at the location in your app where the user’s intent is resolved. Look at the image below to understand how capabilities are the third layer in the application’s outer interface layer:

Understanding the layers in the App architecture

Image #1: Understanding the layers in the App architecture

Steps to Add Capabilities to Your App’s Shortcut (ft. Android 13)

If the targetSDK of your app is more than Android 13, or perhaps Android 12, then you can use the methods below to attach more capabilities to your app’s shortcut.

GeekTip: The shortcuts mentioned here are added in the XML file, which we have already learned in another article about adding shortcuts in Android apps.

To add key dynamics to your currently existing shortcut, do the following:

Step #1: In your Android app development project, shortcuts.xml is a resource file where capability items are defined. 

Step #2: Use the steps in Create static shortcuts to create a shortcuts.xml resource, which is mentioned in the above link.

Step #3: Include the necessary information listed below in your capacity next:

  • Name of the capability: The operation your application should support. For information on the feature that needs capability definitions, consult the component documentation. 
    You have to determine a clear name for your capability name, because if you have a dynamic shortcut then it will land in errors, and will conflict with the app installation, or will create confusion at later stages of development. 
  • App destination: The place in your app to which an action is launched in response to a user request. Use intent components nested within the capability to define app destinations.

Step #4: Organising the dynamic intents (Only to be used if the shortcut is dynamic), map the full shortcuts XML in such a way that the names are unique, otherwise it will get difficult to work on your app at later stages of development. Here is an example of an app, that shows how the courses and articles are maintained, you can also use it for reference:

XML




<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
  <capability android:name="actions.intent.COURSE_INTRO">
    <intent
      android:action="android.intent.action.SHOW"
      android:targetPackage="com.SpandanSaxena.gfgShortcuts"
      android:targetClass="com.SpandanSaxena.gfgShortcuts.CourseActivity">
    </intent>
  </capability>
</shortcuts>


That’s it, by doing this you have successfully added a shortcut to the app, and you can successfully build your app and then publish it.

Few points to remember:

  • The destination activity is indicated by the variable android:targetClass: com.SpandanSaxena.gfgShortcuts.CourseActivity.
  • For this intent, the target application package is set through the android:targetPackage attribute.

Conclusive steps after capability addition

Once a capability has been defined, you can increase its functionality by connecting static or dynamic shortcuts to it. The feature being used and the precise terms in a user’s request determine how shortcuts are connected to a capability. Consider a situation where the user says to the device to enroll him/ her in a course from Geeks for Geeks, then you can provide an extension that will then be launched in the form of an intent, which you have created in your shortcut. Directly launching would save a lot of time, and also would save the app warmup time.



Last Updated : 05 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads