Skip to content

Titanium.UI.ShortcutItem

An application shortcut item.

Allows the creation of dynamic application shortcut items which can be set in the app to offer a dynamic behavior at runtime.

Use the Titanium.UI.createShortcutItem method to create a shortcut item and pass it to the Titanium.UI.Shortcut.add method to add it to the application.

Android Static Shortcuts

Google documents how to add static shortcuts here.

In the tiapp.xml file, you will need to add a shortcuts <meta-data/> element to your main activity.

<ti:app>
    <android>
        <manifest>
            <application>
                <activity android:name=".<Yourapplicationname>Activity">
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN"/>
                        <category android:name="android.intent.category.LAUNCHER"/>
                    </intent-filter>
                    <meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
                </activity>
            </application>
        </manifest>
    </android>
</ti:app>

You will also need to create a shortcuts.xml file as shown below, defining all of the app's static shortcuts. This file must reside in the Titanium project's ./platform/android/res/xml folder. Note that XML attributes icon, shortcutShortLabel, shortcutLongLabel, and shortcutDisabledMessage must be defined as string resources under the project's i18n folders or ./platform/android/res/values folders. Attributes targetPackage and targetClass need to be set to your project id and app name.

<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
  <shortcut
    android:shortcutId="my_unique_string_id"
    android:enabled="true"
    android:icon="@drawable/my_shortcut_icon"
    android:shortcutShortLabel="@string/my_shortcut_short_label"
    android:shortcutLongLabel="@string/my_shortcut_long_label"
    android:shortcutDisabledMessage="@string/my_shortcut_disabled_message">
    <intent
      android:action="android.intent.action.VIEW"
      android:targetPackage="<id_from_tiapp_xml>"
      android:targetClass="<id_from_tiapp_xml>.<Yourapplicationname>Activity" />
    <categories android:name="android.shortcut.conversation" />
  </shortcut>
  <!-- Add more shortcuts here. -->
</shortcuts>

iOS Static Shortcuts

Static shortcut items can be set in the <ios> section of the tiapp.xml before launching the app.

Here is an example how to create static application shortcuts in the tiapp.xml:

<ti:app>
    <!-- ... -->
    <ios>
        <plist>  
            <dict>
            <key>UIApplicationShortcutItems</key>
            <array>
                <dict>
                    <key>UIApplicationShortcutItemIconType</key>
                    <string>UIApplicationShortcutIconTypeSearch</string>
                    <key>UIApplicationShortcutItemTitle</key>
                    <string>My title</string>
                    <key>UIApplicationShortcutItemSubtitle</key>
                    <string>My subtitle</string>
                    <key>UIApplicationShortcutItemType</key>
                    <string>my_identifier</string>
                    <key>UIApplicationShortcutItemUserInfo</key>
                    <dict/>
                </dict>
            </array>
            </dict> 
        </plist> 
    </ios>
    <!-- ... -->
</ti:app>

Static shortcuts can be translated in the i18n/<language>/app.xml file. Dynamic shortcuts can be translated by using the methods described in the Wiki.

Extends: Titanium.Proxy · Since: 7.5.0, 9.1.0, 9.1.0 · Platforms: android, iphone, ipad, macos

Properties #

apiName#

extended

Type: String

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Button
returns Ti.UI.Button.

bubbleParent#

extended

Type: Boolean

Indicates if the proxy will bubble an event to its parent.

Some proxies (most commonly views) have a relationship to other proxies, often
established by the add() method. For example, for a button added to a window, a
click event on the button would bubble up to the window. Other common parents are
table sections to their rows, table views to their sections, and scrollable views
to their views. Set this property to false to disable the bubbling to the proxy's parent.

data#

creation only

Type: Object

Shortcut data.

Additional data that can be stored with the shortcut.

description#

creation only

Type: String

Description of the shortcut.

In iOS the description can be localized. See here
for more infos.

icon#

creation only

Type: String, Number

Shortcut icon.

This can be set as a resource id or file path.

In iOS, you can use constants Titanium.UI.iOS.SHORTCUT_ICON_TYPE_* or a reference to a
Titanium.Contacts.Person as well. On iOS 13 and higher, you can pass in the Ti.Blob instance returned from <Ti.UI.iOS.systemImage> also.

In iOS, if you are using an image file, enable slicing (adding the image to an asset catalog) for
the project. To enable slicing, add the use-app-thinning element to the ios element in the
tiapp.xml file and set the value to true. If you do not enable slicing, the image will
not be displayed.

<ti:app>
    <ios>
    <use-app-thinning>true</use-app-thinning>
    </ios>
</ti:app>

The recommended size for image files is 35dp (@2px: 70dp, @3x: 105dp). Also check the Apple documentation
for more information on shortcut icons.

id#

creation only

Type: String

Determines shortcut id.

This should be a unique identifier for the shortcut.

lifecycleContainer#

extended

Type: Titanium.UI.Window, Titanium.UI.TabGroup

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks
will also be called on the proxy. Proxies that require the activity lifecycle will need this property set
to the appropriate containing Window or TabGroup.

title#

creation only

Type: String

Title of the shortcut.

In iOS the title can be localized. See here
for more infos.

visible (deprecated)#

Type: Boolean

Shortcut visibility.

Determines if the shortcut is visible.

Methods #

addEventListener #

extended

Adds the specified callback as an event listener for the named event.

Parameters:
NameTypeSummaryOptional
nameStringName of the event.No
callbackCallback<Titanium.Event>Callback function to invoke when the event is fired.No

applyProperties #

extended

Applies the properties to the proxy.

Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that
myproxy[key] = value.

Parameters:
NameTypeSummaryOptional
propsDictionaryA dictionary of properties to apply.No

fireEvent #

extended

Fires a synthesized event to any registered listeners.

Parameters:
NameTypeSummaryOptional
nameStringName of the event.No
eventDictionaryA dictionary of keys and values to add to the Titanium.Event object sent to the listeners.Yes

hide #

Hide the shortcut.

pin #

Pin shortcut to launcher.

removeEventListener #

extended

Removes the specified callback as an event listener for the named event.

Multiple listeners can be registered for the same event, so the
callback parameter is used to determine which listener to remove.

When adding a listener, you must save a reference to the callback function
in order to remove the listener later:

var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);

To remove the listener, pass in a reference to the callback function:

window.removeEventListener('click', listener);
Parameters:
NameTypeSummaryOptional
nameStringName of the event.No
callbackCallback<Titanium.Event>Callback function to remove. Must be the same function passed to addEventListener.No

show #

Allow the shortcut to show.

Titanium SDK Documentation