Titanium.Android.Intent
> Titanium.Android.Intent

Message objects passed between Android application components.

In Android, applications and application components cannot directly communicate with each other. In order to communicate with another application, use an intent. An intent is a message sent to the Android OS. Android directs the message to an application or application component based on the intent's settings.

To receive an intent, an application needs to declare an Intent Filter. An intent filter indicates to the Android OS that your application can handle certain data types or URIs. For details on using Intent Filters, see the Android Intent Filters guide.

Intents can be used to start an activity, start a service or start a broadcast.

You can create either an implicit intent or an explicit intent.

An explicit intent specifies the application or application component to launch. To create an explicit intent, specify the Intent's className and packageName properties to specify the application component to launch or the url property to specify a JavaScript file to handle the data.

An implicit intent does not specify a particular application. Android will present the options to the user of which applications to launch if a default application was not selected to handle a particular data type or content URI. To create an implicit intent, do not specify the className, packageName or url properties.

Note that the parameters to create a Service Intent are different than the ones used to create an Activity or Broadcast. The properties and methods listed below are used for Activity and Broadcast Intents. See the Titanium.Android.createServiceIntent method for the parameters to create a Service Intent.

Action

The action property specifies the action you want the activity to perform, or in the case of broadcasts, the action that just completed you want to report.

Titanium exposes some of the Android Intent actions as the Titanium.Android.ACTION_* constants. Note that some of these actions are for system-level broadcasts that only Android can send. If Titanium has not exposed a particular constant, you can pass the string value listed in the Android API reference guide instead.

You can also define your own custom action names. Use a reverse domain scheme to name the action to avoid potential conflicts, for example, com.appcelerator.action.LINT. Custom actions are only useful to communicate between your applications and application activities using intents.

Data

The data property specifies a content URI you want the activity to handle.

The type property specifies a MIME type the activity can handle.

For Broadcast Intents, do not use the data or type properties. Use extras to pass data. See the Extras section below.

Category

Add a category to your Intent by invoking the addCategory() method on it. A category provides additional details about the purpose of the intent. Note that most categories are only useful for intent filters.

Titanium exposes some of the Android Intent categories as the Titanium.Android.CATEGORY_* constants. Note that some of these categories are for Notifications. If Titanium has not exposed a particular constant, you can pass the string value listed in the Android API reference instead.

You can also define your own custom category names. Use a reverse domain scheme to name the category to avoid potential conflicts, for example, org.foo.category.SUPER. Custom categories are only useful to communicate between your applications and application activities using intents.

Flags

Bitwise-OR flags with the Intent's flags property or pass a flag to the addFlags() method. Flags modify the behavior of the intent.

Titanium exposes some of the Android Intent flags as the Titanium.Android.FLAG_* constants. If Titanium has not exposed a particular constant, you can pass the constant value listed in the Android API reference instead.

Extras

Extras are key-value pairs that are useful to pass on extra data with the Intent that can be used by another application component.

  • Use one of the get*Extra() methods to retrieve the data. Pass the method the extra key.
  • Use the hasExtra() method to check if the intent contains an extra. Pass the method the key of the extra.
  • Use the putExtra() method to add data to the intent. Pass the method the extra key and data.

Titanium exposes the Android-defined extra keys as the Titanium.Android.EXTRA_* constants. You can also define your own custom extra keys to use between your applications and application components.

Further Reading

Examples

Create an Intent for Launching an Activity

This example creates an intent and uses it to launch a new activity.

var intent = Ti.Android.createIntent({
    action: Ti.Android.ACTION_MAIN,
    url: 'activity1.js'
});
intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);
Ti.Android.currentActivity.startActivity(intent);

Create an Intent to get a Contact URI

This example creates an intent to retrieve contact information from the user's contacts.

var intent = Ti.Android.createIntent({
    action: Ti.Android.ACTION_GET_CONTENT,
    type: "vnd.android.cursor.item/phone"
});

Pick a Photo from the Photo Gallery

This example creates an intent to pick an image from the photo gallery.

var intent = Ti.Android.createIntent({
    action: Ti.Android.ACTION_PICK,
    type: "image/*"
});
intent.addCategory(Ti.Android.CATEGORY_DEFAULT);

Create an ImageView from an Image Send Intent

This example requires that an intent filter be set up in the project's tiapp.xml file. After copying the default root activity of your application from the AndroidManifest.xml file to the Android manifest section of the tiapp.xml file, add an intent filter. For detailed instructions, refer to the Android Intent Filters guide.

You can trigger this intent filter by long pressing on an image in the Android gallery and selecting "share".

tiapp.xml:

<ti:app>
    <android>
        <manifest>
            <application>
                <activity android:name=".YourapplicationnameActivity">
                    <intent-filter>
                        <data android:mimeType="image/*"/>
                        <action android:name="android.intent.action.SEND"/>
                        <category android:name="android.intent.category.DEFAULT"/>
                    </intent-filter>
                </activity>
            </application>
        </manifest>
    </android>
</ti:app>

app.js:

 var win = Ti.UI.createWindow({
     backgroundColor: '#fff',
     fullscreen: false,
     exitOnClose: true
 });
 win.addEventListener('open', function(e) {
     var intent = Ti.Android.currentActivity.getIntent();
     var iname = Ti.Android.EXTRA_STREAM;
     if (intent && intent.hasExtra(iname)) {
         // Create ImageView from TiBlob
         var blob = intent.getBlobExtra(iname);
         win.add(Ti.UI.createImageView({
             image: blob,
             height: 300,
             width: 300,
             left: 0,
             top: 0
         }));
     } else {
         Ti.API.info('No extra named "' + iname + '" found in Intent');
     }
 });
 win.open();
  • 1.5
Defined By

Properties

Titanium.Android.Intent
action : StringCreation-Only

The action associated with this intent.

The action associated with this intent.

Specify one of the ACTION constants from Titanium.Android, or an application-specific custom action string.

apiName : Stringreadonly

The name of the API that this proxy corresponds to.

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.

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

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.

Default: true

  • 3.0.0
  • 3.0.0
  • 3.0.0
Titanium.Android.Intent
className : StringCreation-Only

The Java class name of the activity associated with this intent (packageName must also be set).

The Java class name of the activity associated with this intent (packageName must also be set).

Titanium.Android.Intent
data : StringreadonlyCreation-Only

The Intent's Data URI.

The Intent's Data URI.

The data URI can be set when the intent is created. It is read-only after the intent is created.

For more information on data URIs, see: Intent.setData in the Android API Reference

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

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.

  • 3.6.0
Titanium.Android.Intent
packageName : StringCreation-Only

The fully-qualified Java package name of the activity.

The fully-qualified Java package name of the activity.

Titanium.Android.Intent
type : StringreadonlyCreation-Only

The MIME type for this Intent.

The MIME type for this Intent.

The MIME type can be set when the intent is created. It is read-only after the intent is created.

For information on MIME types and intents, see: Intent.setType in the Android API Reference.

Titanium.Android.Intent
url : StringCreation-Only

The URL to a Titanium JavaScript Activity.

The URL to a Titanium JavaScript Activity.

Defined By

Methods

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

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

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to invoke when the event is fired.

Returns

  • void
Titanium.Android.Intent
( flags )
Adds to the existing flags on the Intent. ...

Adds to the existing flags on the Intent.

The specified flag are combined with the existing flags using a bitwise OR.

Parameters

Returns

  • void
Applies the properties to the proxy. ...

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.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • props : Dictionary

    A dictionary of properties to apply.

Returns

  • void
Fires a synthesized event to any registered listeners. ...

Fires a synthesized event to any registered listeners.

Parameters

  • name : String

    Name of the event.

  • event : Dictionary

    A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Returns

  • void
Titanium.Android.Intent
( ) : String
Gets the value of the action property. ...

Gets the value of the action property.

Returns

  • String
Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Titanium.Android.Intent
( name ) : Titanium.Blob
Get a Titanium.Blob property from this Intent. ...

Get a Titanium.Blob property from this Intent.

  • 2.1.0

Parameters

Returns

Titanium.Android.Intent
( name ) : Boolean
Get a boolean property from this Intent. ...

Get a boolean property from this Intent.

Parameters

  • name : String

    Property to get.

Returns

  • Boolean
Gets the value of the bubbleParent property. ...

Gets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Returns

  • Boolean
Titanium.Android.Intent
( ) : String
Gets the value of the className property. ...

Gets the value of the className property.

Returns

  • String
Titanium.Android.Intent
( ) : String
Gets the value of the data property. ...

Gets the value of the data property.

Returns

  • String
Titanium.Android.Intent
( name ) : Number
Get a double property from this Intent. ...

Get a double property from this Intent.

Parameters

  • name : String

    Property to get.

Returns

  • Number
Titanium.Android.Intent
( ) : Number
Gets the value of the flags property. ...

Gets the value of the flags property.

Returns

  • Number
Titanium.Android.Intent
( name ) : Number
Get an integer property from this Intent. ...

Get an integer property from this Intent.

Parameters

  • name : String

    Property to get.

Returns

  • Number
Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.Android.Intent
( name ) : Number
Get a long property from this Intent. ...

Get a long property from this Intent.

Parameters

  • name : String

    Property to get.

Returns

  • Number
Titanium.Android.Intent
( ) : String
Gets the value of the packageName property. ...

Gets the value of the packageName property.

Returns

  • String
Titanium.Android.Intent
( name ) : String
Get a string property from this Intent. ...

Get a string property from this Intent.

Can also be used to get the string representation of a property that's stored as an Android Parcel, such as a URI.

Titanium does not support getParcelableExtra due to the inability to translate all of its possible return types to JavaScript.

See also: [getParcelableExtra](http://developer.android.com/reference/android/content/Intent.html#getParcelableExtra(java.lang.String) in the Android Developer Reference.

Parameters

  • name : String

    Property to get.

Returns

  • String
Titanium.Android.Intent
( ) : String
Gets the value of the type property. ...

Gets the value of the type property.

Returns

  • String
Titanium.Android.Intent
( ) : String
Gets the value of the url property. ...

Gets the value of the url property.

Returns

  • String
Titanium.Android.Intent
( name ) : Boolean
Returns true if this Intent has the specified property. ...

Returns true if this Intent has the specified property.

Parameters

  • name : String

    Property name to check for.

Returns

  • Boolean
Titanium.Android.Intent
( name, value )
Puts an extra property on this Intent. ...

Puts an extra property on this Intent.

Parameters

  • name : String

    Name of the property to add.

  • value : Object

    Property value to set.

Returns

  • void
Titanium.Android.Intent
( name, value )
Put a URI property on this Intent (useful for Titanium.Android.EXTRA_STREAM). ...

Put a URI property on this Intent (useful for Titanium.Android.EXTRA_STREAM).

Parameters

  • name : String

    The property name.

  • value : Object

    The URI, as a string or a string array.

Returns

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

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

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to remove. Must be the same function passed to addEventListener.

Returns

  • void
Titanium.Android.Intent
( action )
Sets the value of the action property. ...

Sets the value of the action property.

Parameters

  • action : String

    New value for the property.

Returns

  • void
Sets the value of the bubbleParent property. ...

Sets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • bubbleParent : Boolean

    New value for the property.

Returns

  • void
Titanium.Android.Intent
( className )
Sets the value of the className property. ...

Sets the value of the className property.

Parameters

  • className : String

    New value for the property.

Returns

  • void
Titanium.Android.Intent
( flags )
Sets the value of the flags property. ...

Sets the value of the flags property.

Parameters

  • flags : Number

    New value for the property.

Returns

  • void
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void
Titanium.Android.Intent
( packageName )
Sets the value of the packageName property. ...

Sets the value of the packageName property.

Parameters

  • packageName : String

    New value for the property.

Returns

  • void
Titanium.Android.Intent
( url )
Sets the value of the url property. ...

Sets the value of the url property.

Parameters

  • url : String

    New value for the property.

Returns

  • void