app.SendIntent ??

881 views
Skip to first unread message

Vinetwigs.

unread,
Jun 3, 2016, 12:49:10 PM6/3/16
to DroidScript
Can somebody explain me the app.SendIntent option?
I'm new in the world of DroidScript.

Gerard Hernandez

unread,
Jun 3, 2016, 2:07:39 PM6/3/16
to DroidScript
Welcome to the DS community, I hope you get a lot of fun and learning with this great tool.

The first thing is, do you have prior knowledge with Intents in Java Android??

If no, please look in the official android documentation for more precise info.

In DS you send a intent like this.

app.SendIntent(Package, ActivityClass, Action, Category, URI_OR_DATA, Type, Extras, Options Result);
All params are Strings, except Extras that is a JSON object and Result, that is a callback with the signature function(resultCode,result)

If you want to open whatapp app (i.e)
you do this.

app.SendIntent("com.whatsapp","com.whatsapp.Main","android.intent.action.VIEW");

If you want a quick introduction, read ahead.


Activities are the base of the android application system. You can use activities for almost everything. 

Applications in android are delivered as packages (apk => Android Application Package). and packages may contain a lot of bits of code, including classes. The Activities are the foundation for the UI part of the apps.

In order to the system to be able to detect, manage and display your activities, you need to define them in the manifest of your app.

But at this moment android os in your device already have a lot of applications installed , including default activities for certain task or Intent,

there are implicit and explicit intents. implicit only need to define action/category where explicit need the package/activity as well.

Intents are specified like this.
  • PackageName  The name of the app package, If you want to a specific app handle the intent this need to be defined.
  • ActtivityClassName. The name of the activity class, if you want to a specific activity handle is called, define it, use it with packagename
  • Action. The action defined in the intent filter for the activity. A common one is android.intent.action.VIEW, used to open a activity, but others can be used like android.intent.action.SEND for sms or whatapp or others for things like sharing, taking images, picking contacts.
  • Category. Like action, this allow to group a lot of common purpose actions in different groups. like android.intent.category.DEFAULT or LAUNCHER
  • Data or URI. The first and main piece of data to send to the intent, this may include the base scheme (defined in the manifest too). an example like "tel:5559990000" or "sms:5559990000" or "http://www.google.com", please not that http its a protocole, but in the word of your device, where different stuff is marked as a resource and have an URI. http, or file, or ftp or mailto represent the way the data should be treated. schemme vs protocol is a long debate in the w3, but at least in your device tiny universe, http is a resource. End of rant.
  • Type.  the mime type of the data, things like text/plain or more complicated like vnd.android.cursor.item/vnd.google.memory.note. etc.
  • Extras. a bundle of additional information send within the intent,



Vinetwigs.

unread,
Jun 3, 2016, 2:32:10 PM6/3/16
to DroidScript
Thank you so much.
Your explaination is very good...can you tell me some practice applications Please?
(Sorry for my English)

Gerard Hernandez

unread,
Jun 3, 2016, 4:25:55 PM6/3/16
to DroidScript
well, first of all to get full usage of intents youll need to wait for the next release as it include support ot handle intent results.
This is usefull for picking a contact info, launching the camera and getting the file URI back.

In the meanwhile you can, among other things.

Open other apps
Unistall other apps.
Create contacts
edit Contacts
Open whatsapp conversation screen
start default camera
start default music player
open gallery
open maps app with a location

others and me have added some useful samples.

DAVID SEE

unread,
Jul 28, 2018, 6:55:52 PM7/28/18
to DroidScript
Can anyone help with the following Droidscript Code
This code did not insert any new contact, what wrong with my code?
Thank You anyway if someone can to correct it

=======================================================
//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
//Create a button 1/3 of screen width and 1/10 screen height.
btn = app.CreateButton( "Send ", 0.3, 0.1 );
btn.SetOnTouch( btn_OnTouch );
lay.AddChild( btn );

//Add layout to app.
app.AddLayout( lay );
}

//Called when user touches our button.
function btn_OnTouch()
{
    var packageName = "com.android.contacts";
    var className = null;
    var action = "android.intent.action.INSERT";
    var category = "DEFAULT";
    var uri =  "prop0...@gmail.com";
    var type = "CONTENT_TYPE";
    var extras = [ 
        {name:"android.intent.extra.Insert.NAME", type:"CONTENT_TYPE", value:"#AAAAB"},
        {name:"android.intent.extra.Insert.PHONE", type:"CONTENT_TYPE", value:"99999999"},
       ];

           
        
       app.SendIntent(packageName, className, action, category, uri, type, extras ); 
}
=================================================================
Reply all
Reply to author
Forward
0 new messages