The Intent API provides an inter-application broadcast message-passing framework. ## Enabling the API This API is part of the `coreapi` extension that is included automatically. :::ruby extensions: ["coreapi"] ## JavaScript Usage Be sure to review the [JavaScript API Usage](/guide/api_js) guide for important information about using this API in JavaScript. ## Ruby Usage Be sure to review the [Ruby API Usage](/guide/api_ruby) 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: :::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 :::ruby android: no_compression: ['pdf','html','css'] A hash-map with intent parameters. Type of Intent to send. Use the intent as broadcast intent. Use the intent to start a UI activity. Android Use the intent to start a background service. Android Android Permission used to send a broadcast intent. Android Intent action. See Android docs]]> for possible values. Use the Constant Value instead of the actual Constant Name. For example, for the ConstantACTION_PICK]]> use 'android.intent.action.PICK' instead. Android List 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. Explicit name of the application to run on the device. The platform will determine the value to use. * iOS it is BundleURLScheme of executed application. * Android it is application package name. * Windows it is the application/executable name. For shared runtime based applications, the application name is taken from the "Name" attribute from the Config.xml file. Hence use the application name which is mentioned in config.xml. Android Explicit name of the class in the application that will receive the intent. Must be specified if and only if 'appName' is defined. Open 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 Map Intent, you might set this value to something like 'geo:47.6,-122.3.']]> MIME type of data defined in the intent. For example, for Plain Text one would use 'text/plain.' On Android, this is similar to Intent.setType.]]> Data to be sent within the intent. On Android, this is similar to Intent.putExtra, and 'data' should contain a HASH of Extra-String/Value pairs. The 'Value' type of the 'Extra' can be a String, Integer, Boolean or Double. Other object types are not supported at this time. For sample code, please refer to examples section, below. Use the full constant string 'android.intent.extra.TEXT' in place of Intent.EXTRA_TEXT.]]> Wrap the intent in an action chooser that display the list of available services that can handle the intent. See : Intent.createChooser.]]> Set the chooser title if 'createChooser' is enabled. See : Intent.createChooser.]]> Same format as 'params' argument and some additional values described below. Android: Developer has to ensure that the response is addressed to this call because of possible conflicts in integer request code with other extensions. Android Response code passed to Android Activity.setResult() method. RESULT_OK = -1. Check Android Docs]]> for more information. Other attributes, such as 'uri' may be returned depending on the Intent that was triggered. Possible parameters include the same params that are used in this 'send(params)' method. Start listening for custom intents. For Android, this is how we have implemented [Android Intent Filters](http://developer.android.com/guide/components/intents-filters.html#Receiving). In order to listen for Intents you will have to update the `AndroidManifest.erb` file and add a special section to it. This file is now generated with RhoMobile Version 4.1 when you create a new project. The file is located in the root of project. Add the following snippet to AndroidManifest.erb within the `manifest` tags ]]> Notice that this looks very similar to a standard AndroidManifest.XML file section except the `receiver` is the common RhoMobile intent receiver. The `intent-filter` tags within this section are standard AndroidManifest.XML notation that you would put in for the Intent-Filters that you want to listen for. Consult the [Android Docs](http://developer.android.com/guide/components/intents-filters.html#Receiving) for more information about Intent Filters. From your Android application, you would use the [sendBroadcast() method](http://developer.android.com/reference/android/content/Context.html#sendBroadcast(android.content.Intent\)) with the appropriate parameters for this filter. Same format as 'params' argument passed to Rho.Intent.send method Android: Developer has to ensure that an intent passed to handler is what he intended to proceed since any other intent may also be passed here. Stop listening for custom intents. Android Stop listening for custom intents. Intent Guide for more information. ]]> 4.1.0 iOS, WM, Android
You can use the Intent API to use the default mapping program to plot locations. 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 function sendGeo(){ var intentParams = {action : "android.intent.action.VIEW", intentType : Rho.Intent.START_ACTIVITY, uri : "geo:37.422, -122.084"}; Rho.Intent.send(intentParams); }
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. 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 function webSearch(){} var intentParams = {action : "android.intent.action.WEB_SEARCH", intentType : Rho.Intent.START_ACTIVITY, data : {query : "Rhomobile docs"}} Rho.Intent.send(intentParams) }