The Intent API provides an inter-application broadcast message-passing framework.
This API is part of the coreapi extension that is included automatically.
:::ruby
extensions: [“coreapi”]
Be sure to review the JavaScript API Usage guide for important information about using this API in JavaScript.
Be sure to review the Ruby API Usage guide for important information about using this API in Ruby.
Sends an intent. The receiver of the intent can either be another RhoMobile application that is listening for this Intent characteristic or on Android can be a native Android application setup with an Intent-Filter that will trigger based on the parameters of this method.
Android Note: On Android, the callback should be used only when the intentType is set to START_ACTIVITY. The only valid way for an Android app to pass a private file from a package directly to another application is to set the ‘uri’ parameter with content URI:
Sample JavaScript:
var params = { intentType: Rho.Intent.START_ACTIVITY, action: "ACTION_VIEW", uri: "content://com.rhomobile.sample/rhodata/apps/public/sample.pdf" } Rho.Intent.send(params);
In most cases the extension of the exported file also must be added to the ‘android:no_compression’ list in the build.yml:
Sample Build.yml
android: no_compression: ['pdf','html','css']





Parameters
A hash-map with intent parameters.
Type of Intent to send.
Possible Values :
Use the intent as broadcast intent.
Use the intent to start a UI activity.
Platforms:Android
Use the intent to start a background service.
Platforms:Android
Permission used to send a broadcast intent.
Platforms:AndroidIntent action. See Android docs for possible values. Use the Constant Value instead of the actual Constant Name. For example, for the Constant ACTION_PICK use ‘android.intent.action.PICK’ instead.
Platforms:AndroidList of intent categories. See Android docs for possible values. Use the Constant Value instead of the actual Constant Name. For example, for the Constant CATEGORY_HOME use ‘android.intent.category.HOME’ instead.
Platforms:Android
Explicit name of the application to run on the device. The platform will determine the value to use.
Explicit name of the class in the application that will receive the intent. Must be specified if and only if ‘appName’ is defined.
Platforms:AndroidOpen the application associated with the URI. Behavior may be different on different platforms and on software installed. For example, open URL with ‘http://’ prefix usually executes the Web Browser installed on system and opens the URL in that browser. On Android, this is similar to Intent.setData(). For example, if sending a <




Parameters
Async Callback Returning Parameters: HASH
Synchronous Return:
Method Access:
Rho.Intent.startListening(CallBackHandler callback) Rho::Intent.startListening(CallBackHandler callback)
Stop listening for custom intents.





Synchronous Return:
Method Access:
Rho.Intent.stopListening() Rho::Intent.stopListening()
You can use the Intent API to use the default mapping program to plot locations.
function sendGeo(){ var intentParams = {action : "android.intent.action.VIEW", intentType : Rho.Intent.START_ACTIVITY, uri : "geo:37.422, -122.084"}; Rho.Intent.send(intentParams); }
def send_geo intent_params = {:action => "android.intent.action.VIEW", :intentType => Rho::Intent::START_ACTIVITY, :uri => "geo:37.422, -122.084"} Rho::Intent.send intent_params end
Sometimes you will want to send some extras along with an intent such as an SMS body or do a web search with a given string. Here is an example of an intent that will launch the default web browser and perform a search with the default search engine.
function webSearch(){} var intentParams = {action : "android.intent.action.WEB_SEARCH", intentType : Rho.Intent.START_ACTIVITY, data : {query : "Rhomobile docs"}} Rho.Intent.send(intentParams) }
def web_search intent_params = { :action => "android.intent.action.WEB_SEARCH", :intentType => Rho::Intent::START_ACTIVITY, :data => { :query => "Rhomobile docs" } } Rho::Intent.send intent_params end
For an Android app to receive intent data, the Intent receiver must be registered in the app’s AndroidManifest.erb file. Please refer to the Intent Guide for more information.