General
Intents are a way of communicating between apps, to initiate a specific task or to navigate the user to a different app for various reasons. The used app methods are SendIntent and OpenUrl.
This section is a collection of various examples that illustrate various use cases of intents and related methods.
Default Apps
Example - Default Apps
var categories = [
"android.intent.category.APP_BROWSER",
"android.intent.category.APP_MUSIC",
"android.intent.category.APP_CALCULATOR",
"android.intent.category.APP_CONTACTS",
"android.intent.category.APP_EMAIL",
"android.intent.category.APP_MAPS",
"android.intent.category.APP_GALLERY",
"android.intent.category.APP_CALENDAR",
"android.intent.category.APP_MARKET",
"android.intent.category.APP_MESSAGING",
];
app.SendIntent(null, null, "android.intent.action.MAIN", categories[0]);
URI Intents
Playstore App Page
var packageName = "com.skype.raider";
app.OpenUrl("market:details?id=" + packageName);
Skype: URI documentation
app.OpenUrl("skype:echo123?call");
Standard Apps
GMail
Example - Create Email in GMail App
var packageName = "com.google.android.gm";
var className = "com.google.android.gm.ComposeActivityGmail";
var action = "android.intent.action.VIEW";
var category = null;
var uri = "myfriend@gmail.com";
var type = "message/rfc822";
var extras = JSON.stringify([
{ name: "android.intent.extra.EMAIL", type: "list", value: "fred@gmail.com" },
{ name: "android.intent.extra.SUBJECT", type: "string", value: "My subject" },
{ name: "android.intent.extra.TEXT", type: "string", value: "Hello!" }
]);
app.SendIntent(packageName, className, action, category, uri, type, extras);
Google Maps
Google Maps intent documentation
Example - Basic Maps
function OnStart()
{
var lat = "51.5117";
var lng = "-0.1275";
simpleMap(lat, lng);
}
function simpleMap(latitude, longitude)
{
var packageName = "com.google.android.apps.maps";
var className = null;
var action = "android.intent.action.VIEW";
var uri = "geo:" + latitude + "," + longitude;
app.SendIntent(packageName, className, action, null, uri);
}
Example - Maps Turn by Turn Navigation
function navigateTo(latitude, longitude)
{
var packageName = "com.google.android.apps.maps";
var className = null;
var action = "android.intent.action.VIEW";
var uri = "google.navigation:q=" + latitude + "," + longitude;
if (app.IsAppInstalled(packageName))
app.SendIntent(packageName, className, action, null, uri);
else
app.Alert("maps app not installed");
}
Example - Maps Location
app.SendIntent(
"com.google.android.apps.maps",
null,
"android.intent.action.VIEW",
"android.intent.category.DEFAULT",
"geo:0,0?q=34.5678,123.4567 (Placename)"
);
Phone Calls
Note: package and activity are not required because the dialer app differs among manufacturers and sometimes event among models from same manufacturer.
Example - Phone Call
app.SendIntent(null, null, "android.intent.action.DIAL", null, "tel:5551237654");
app.SendIntent(null, null, "android.intent.action.CALL", null, "tel:5551237654");
SMS
Example - Basic SMS
var number = "0123456789";
var message = "my message";
app.SendIntent(null, null, "android.intent.action.SENDTO",
null, 'smsto:' + number, null,
JSON.stringify([{
name: "sms_body",
type: "string",
value: message
}]));
Camera
Example - Camera Modes
app.SendIntent(null, null, "android.media.action.STILL_IMAGE_CAMERA");
app.SendIntent(null, null, "android.media.action.STILL_IMAGE_CAMERA_SECURE");
app.SendIntent(null, null, "android.media.action.VIDEO_CAMERA");
Settings
The Settings Intent Documentation has a Constants section with available Actions. Replace ACTION_ by android.settings. to get the category parameter.
Example - Settings
app.SendIntent(null, null, "android.settings.BLUETOOTH_SETTINGS" )
app.SendIntent(null, null, "android.settings.WIFI_SETTINGS" )
Misc
Example - Add Calendar Event
function cal_si_insert()
{
var today = Date.now();
var extras = [
{ name: "description", type: "string", value: "DS SendIntent Description" },
{ name: "title", type: "string", value: "DS SendIntent Title" },
{ name: "beginTime", type: "long", value: today },
{ name: "eventLocation", type: "string", value: "DS SendIntent Address" },
{ name: "endTime", type: "long", value: today + 3600000 },
];
extras = JSON.stringify(extras);
app.SendIntent(null, null, "android.intent.action.INSERT", null,
"android.intent.Events.CONTENT_URI", "vnd.android.cursor.item/event", extras);
}
Example - Receive Broadcasts
function OnStart()
{
app.EnableBackKey(false);
app.SetOnBroadcast(rb, "android.intent.action.HEADSET_PLUG");
app.SetOnBroadcast(rb, "android.intent.action.SOUND_SETTINGS");
app.SetOnBroadcast(rb, "android.media.VOLUME_CHANGED_ACTION");
app.SetOnBroadcast(rb, "android.intent.action.TIME_TICK");
app.SetOnBroadcast(rb, "android.AccessibilityService.FINGERPRINT_GESTURE_SWIPE_DOWN");
app.SetOnBroadcast(rb, "android.action.CAMERA_BUTTON");
app.SetOnBroadcast(rb, "android.action.MEDIA_BUTTON");
app.SetOnBroadcast(rb, "android.bluetooth.a2dp.profile.action.CONNECTION_STATE_CHANGED");
app.SetOnBroadcast(rb, "android.bluetooth.adapter.action.CONNECTION_STATE_CHANGED");
app.SetOnBroadcast(rb, "android.bluetooth.adapter.action.DISCOVERY_FINISHED");
app.SetOnBroadcast(rb, "android.bluetooth.adapter.action.DISCOVERY_STARTED");
app.SetOnBroadcast(rb, "android.bluetooth.adapter.action.LOCAL_NAME_CHANGED");
app.SetOnBroadcast(rb, "android.bluetooth.adapter.action.SCAN_MODE_CHANGED");
app.SetOnBroadcast(rb, "android.bluetooth.adapter.action.STATE_CHANGED");
app.SetOnBroadcast(rb, "android.bluetooth.device.action.ACL_CONNECTED");
app.SetOnBroadcast(rb, "android.bluetooth.device.action.ACL_DISCONNECTED");
app.SetOnBroadcast(rb, "android.bluetooth.device.action.ACL_DISCONNECT_REQUESTED");
app.SetOnBroadcast(rb, "android.bluetooth.device.action.BOND_STATE_CHANGED");
app.SetOnBroadcast(rb, "android.bluetooth.device.action.CLASS_CHANGED");
app.SetOnBroadcast(rb, "android.bluetooth.device.action.FOUND");
app.SetOnBroadcast(rb, "android.bluetooth.device.action.NAME_CHANGED");
app.SetOnBroadcast(rb, "android.bluetooth.device.action.UUID");
app.SetOnBroadcast(rb, "android.bluetooth.devicepicker.action.DEVICE_SELECTED");
app.SetOnBroadcast(rb, "android.bluetooth.devicepicker.action.LAUNCH");
app.SetOnBroadcast(rb, "android.bluetooth.headset.action.VENDOR_SPECIFIC_HEADSET_EVENT");
app.SetOnBroadcast(rb, "android.bluetooth.headset.profile.action.AUDIO_STATE_CHANGED");
app.SetOnBroadcast(rb, "android.bluetooth.headset.profile.action.CONNECTION_STATE_CHANGED");
app.SetOnBroadcast(rb, "android.bluetooth.input.profile.action.CONNECTION_STATE_CHANGED");
app.SetOnBroadcast(rb, "android.bluetooth.pan.profile.action.CONNECTION_STATE_CHANGED");
}
function rb(type, msg) {
alert(JSON.stringify(type));
}
function handleReply(error, reply) {
alert(JSON.stringify(error));
alert(JSON.stringify(reply));
}
function OnBack() { app.ToFront(); }
function OnPause() { app.ToFront(); }