How can I call my android app actions defined in shortcuts.xml?

36 views Asked by At

I try to add some app actions to an android project. I created a new project and added meta tag to MainActivity tag in the AndroidManifest.xml.

<activity
    android:name=".MainActivity"
    android:exported="true">

    <meta-data
        android:name="android.app.shortcuts"
        android:resource="@xml/shortcuts" />

Afterwards I created the shortcuts.xml file in res/xml folder. Here is the content of the file.

<capability android:name="actions.intent.START_EXERCISE">
    <intent
        android:action="android.intent.action.VIEW"
        android:targetClass="com.example.automotiveexample.MainActivity"
        android:targetPackage="com.example.automotiveexample">
        <parameter
            android:name="exercise.name"
            android:key="exerciseType" />
    </intent>
</capability>

<shortcut
    android:shortcutId="running"
    android:shortcutShortLabel="@string/activity_running">
    <capability-binding android:key="actions.intent.START_EXERCISE">
        <parameter-binding
            android:key="exercise.name"
            android:value="@array/runningSynonyms" />
    </capability-binding>
</shortcut>


<capability android:name="actions.intent.OPEN_APP_FEATURE">
    <intent
        android:action="android.intent.action.VIEW"
        android:targetClass="com.example.automotiveexample.MainActivity"
        android:targetPackage="com.example.automotiveexample">
        <parameter
            android:name="feature"
            android:key="@string/app_name" />
    </intent>
</capability>

<capability android:name="actions.intent.CREATE_THING">
    <intent
        android:action="android.intent.action.VIEW"
        android:targetClass="com.example.automotiveexample.MainActivity"
        android:targetPackage="com.example.automotiveexample">
        <!-- Eg. name = "Example Entity" -->
        <parameter
            android:name="thing.name"
            android:key="name" />
        <!-- Eg. description = "Example Destination" -->
        <parameter
            android:name="thing.description"
            android:key="description" />
    </intent>
</capability>
0

There are 0 answers