But i don't know how to launch applications via variable..
So that whenever i say "Open 'App name' " It will find appropriate matching for that application and open it.
(Sorry for bad english)
~Peter
(If you are a premium users, look at the Launcher sample, If not, I recommend to become premium)
I tried this, but I was unable to figure out what IndexOf () statement does. ('Cause I'm new to javascript / droidscript) ...
Explanation will be more helpful with examples.
Thanks.
I am not sure that Nikhil's suggestion will give you enough information to use the activities list. Personally for your purposes I would build some sort of index
The code below is not entirely aimed at a beginner either but the buildIndex function may be useful to you.
//
var activities;
function OnStart()
{
lay = app.CreateLayout("Linear", "VCenter,FillXY");
edt = app.CreateTextEdit("Gmail", -1, -1, "singleLine");
edt.SetOnEnter(openApp);
lay.AddChild(edt);
app.AddLayout(lay);
activities = buildIndex(app.GetActivities());
edt.Focus();
app.ShowKeyboard(edt);
}
function openApp()
{
var label = this.GetText().toLowerCase();
var rec = activities[label]
var action = "android.intent.action.MAIN";
if(rec)
{
app.SendIntent(rec.packageName,
rec.className, action);
}
else
{
alert(label + " Not Installed")
}
}
function buildIndex(obj)
{
var len = obj.length;
var rec, newRec, ret = {};
for(var i = 0; i < len; i++)
{
rec = obj[i];
ret[rec.label.toLowerCase()] = {
packageName: rec.packageName,
className: rec.className };
}
return ret
}
I made a slight modified version that lists all installed and launches on touch. Here it is if anyone wants it :D
var activities;
function OnStart()
{
lay = app.CreateLayout("Linear", "VCenter,FillXY");
// edt = app.CreateTextEdit("Gmail", -1, -1, "singleLine");
//edt.SetOnEnter(openApp);
var pkgs = app.GetActivities();
lst = app.CreateList("",1,1,"");
app.ShowProgressBar("Loading...");
for (var i = 0; i < pkgs.length; i++)
{
app.UpdateProgressBar(( i / pkgs.length)*100)
lst.AddItem(pkgs[i].label, pkgs[i].className);
app.ShowPopup(i);
}
lst.SetOnTouch(function (title,body,image,index){
this.title = title;
this.body = body;
this.image = image;
this.index = index;
openApp(this.title)
});
app.HideProgressBar()
lay.AddChild(lst)
// lay.AddChild(edt);
app.AddLayout(lay);
activities = buildIndex(app.GetActivities());
// edt.Focus();
lst.Focus()
// app.ShowKeyboard(edt);
}
function openApp(item)
{
this.item = item
var label = this.item.toLowerCase();
var rec = activities[label]
var action = "android.intent.action.MAIN";
if(rec)
{
app.SendIntent(rec.packageName,
rec.className, action);
}
else
{
alert(label + " Not Installed")
}
}
function buildIndex(obj)
{
var len = obj.length;
var rec, newRec, ret = {};
for(var i = 0; i < len; i++)
{
rec = obj[i];
ret[rec.label.toLowerCase()] = {
packageName: rec.packageName,
className: rec.className };
}
return ret;
}