details about app.StartApp?

234 views
Skip to first unread message
Message has been deleted

Steve Garman

unread,
Aug 24, 2015, 11:12:20 AM8/24/15
to AndroidScript
The second parameter is "Debug" or "", equivalent to the "Debug" or "Run" buttons in the device IDE.

Any reply I gave you about the intent parameter would be a guess.

Timo Octazid

unread,
Aug 24, 2015, 12:01:29 PM8/24/15
to AndroidScript
Hi,
In the DroidScript.js I found another second parameter: "remote"

Many Greetings
Timi

Dave Smart

unread,
Aug 25, 2015, 7:44:09 AM8/25/15
to AndroidScript
Hi Guys,

The 'remote' and 'debug' parameters are really intended for internal use by DS. They tell the started App to broadcast errors and debug information to the main DS IDE and/or Wifi IDE.  

The 'intent' parameter allows the DS IDE to forward intent information on to your App when your App is not running as an APK (so that you can test intent handling without making an APK)

I don't think these options will be very useful to anyone really, except maybe if you were writing a script launcher App.

Regards
David
Message has been deleted

John Calder

unread,
Apr 2, 2019, 5:21:08 AM4/2/19
to DroidScript
I am writing a script launcher app.
I read that I can send "intent" data as a json string when I start another app.

app.StartApp(file, options, num_intent);

Please, how do I receive this data in the target app?

This will run as scripts in the first planned deployments so the APK issues I am reading about here are not of immediate concern.
The phone is acting as a wildlife surveillance camera with security camera also a possibility.
The main app is based on the "Camera Motion" example packaged with the DroidScript IDE.
I am monitoring nocturnal pests like rats so I want the script launcher app to turn it on at night and off in the morning as a power saving strategy.
Is app.StartApp ... the only way of achieving this?

Regards, John




Dave

unread,
Apr 3, 2019, 7:57:36 AM4/3/19
to DroidScript
Hi John,

It would probably be simpler to create a background service to start and stop your main app when needed.

Check out the Background Service template (available in the wifi editor) or in the latest alpha of DS http://androidscript.org/alpha/DroidScript_173a4/ or if you are not premium, search for Background service examples on this forum.

Also the premium forum has a good example of how to create a watchdog service which will probably be ideal as a starting point for you

John Calder

unread,
Apr 12, 2019, 4:15:34 AM4/12/19
to DroidScript
I did get this to work with
In app launcher:

app.StartApp("/sdcard/DroidScript/childCam/childCam.js", "", json);

Then in the child app "childCam.js"

var oSettings = app.GetIntent();


Some feedback and questions from trials so far.
 
app.StopApp does not work for me. There is no response.
I can only stop the child app by writing a "stop" command to the clipboard and the child app polls for that then does app.Exit();

app.CreateImage does not work when the screen is black/locked. It returns a null.
This is currently blocking my effort to do motion detection at night only via an app launcher.

This script launcher needs a user interface and as far as I know the "Services" do not provide that.
Would launching from a "Service" make any difference to app.CreateImage not working when launched unattended with the screen locked?



John Calder

unread,
Apr 12, 2019, 8:07:12 AM4/12/19
to DroidScript
Trying simpler test apps run by a launcher using app.StartApp

app.GetClipBoardText() is not working for me when the screen is locked.

The debug panel says

WARNING: App.GetClipboardText() failed! (Attempt to invoke interface method 'java.lang.String java.lang.CharSequence.toString()' on a null object reference)

Dave

unread,
Apr 13, 2019, 7:58:24 AM4/13/19
to DroidScript
Hi John,

You don't need an image control to do motion detection... that's just to show a nice display for the user.

Here is an example that does not use the imageview and also repeatedly restarts the camera app for 10 seconds, then shuts down the app and re-awakes it again after another 10 seconds:-

(Older phones might work better with this code because the latest versions of Android tend to restrict the use of wakelocks and alarms)


//Initialise some variables.
var sensitivity = 50; //percent.
var minPeriod = 500;  //millisecs.
var mosaic = "3x3";
var snapFolder = "/sdcard/Snaps";
 
//Called when application is started.
function OnStart()
{  
   
//Wake up the phone.
   
//(This can be quite slow, make sure lock screen is disabled)
    app
.Unlock();
   
 
//Fix orientation to landscape since
 
//most phones cameras work this way.  
 app
.SetOrientation( "Landscape" );
   
 
//Create horizontal layout that fills the screen.
 lay
= app.CreateLayout( "Linear", "Horizontal,FillXY" );
 
 
//Create frame layout on left for camera view.
 layLeft
= app.CreateLayout( "Frame" );
 layLeft
.SetMargins( 0,0.1,0.02,0 );
 lay
.AddChild( layLeft );
   
 
//Create camera view control.
 cam
= app.CreateCameraView( 0.4, 0.8 );
 layLeft
.AddChild( cam );  


 
//Create vertical layout on right for other stuff.
 layRight
= app.CreateLayout( "Linear", "Vertical" );
 lay
.AddChild( layRight );
 
 
//Create a text control to show logs.
 txt
= app.CreateText( "", 0.5, 0.4, "Multiline,Left" );
 txt
.SetMargins( 0,0.1,0,0 );
 txt
.SetPadding( 0.01,0.01,0.01,0.01 );
 txt
.SetTextColor( "#ffffffff" );
 txt
.SetBackColor( "#ff222222" );
 layRight
.AddChild( txt );


 
//Create sensitivity seek bar label.
 txtSens
= app.CreateText( "Sensitivity" );
 txtSens
.SetMargins( 0,0.05,0,0 );
 layRight
.AddChild( txtSens );
 
 
//Create sensitivity seek bar.
 skb
= app.CreateSeekBar( 0.3, -1 );
 skb
.SetOnTouch( skb_OnTouch );
 skb
.SetValue( sensitivity );
 layRight
.AddChild( skb );
 
 
//Create mosaic spinner label.
 txtTiles
= app.CreateText( "Mosaic" );
 txtTiles
.SetMargins( 0,0.05,0,0 );
 layRight
.AddChild( txtTiles )
 
 
//Create mosaic spinner.
 
var layouts = "3x2,3x3,5x5,10x10";
 spin
= app.CreateSpinner( layouts, 0.2, -1 );
 spin
.SetOnTouch( spin_OnTouch );
 spin
.SetText( "3x3" );
 layRight
.AddChild( spin );
 
 
//Set menus.
 app
.SetMenu( "Snap,Exit" );    
 
 
//Add main layout to app.
 app
.AddLayout( lay );
 
 
//Start capture after 1 second.
 setTimeout
( "StartDetection()", 1000 );
 
 
//Shut down the app again after 10 seconds.
    setTimeout
( function(){ app.Exit() }, 10000 );
   
   
//Wake up the app again after 20 seconds.
   
var now = new Date().getTime();
    app
.SetAlarm( "Set", 1234, null, now+20000 );
}


//Start motion detection.
function StartDetection()
{
 
//Enable 3x3 matrix motion detection and mark
 
//motion detections in the image control.
 cam
.MotionMosaic( 3, 3, (100-sensitivity)/5, minPeriod );
 cam
.SetOnMotion( OnMotion );
 
 
//Create folder for saved pictures and
 
//set image size, counters etc.
 app
.MakeFolder( snapFolder );
 cam
.SetPictureSize( 1024, 768 );
 maxPics
= 10; count = 1;
 
 
//Create array to hold log messages.
 log
= new Array();
 
Log( "Ready" );
 
 
//Start preview.
 cam
.StartPreview();
}




//Handle menu selections.
function OnMenu( name )
{          
   
if( name=="Snap" )
 
Snap();
   
else if( name=="Exit" )
        app
.Exit();  
}


//Called when motion is detected.
//(data contains an array of detection strength
//values corresponding to each mosaic tile)
function OnMotion( data )
{
 
//Show info in log.
 
Log( data );
 
 
//Snap a photo.
 
Snap();
}


//Take a picture and store to sdcard.
function Snap()
{
 
//Limit number of pictures by recycling
 
//the file names.
 
if( count >= maxPics ) count = 1;
 
else count++;
 
 
//Save picture to sdcard.
 
var file = snapFolder+"/Snap"+count+".jpg";
    cam
.TakePicture( file );
   
Log( file );
}


//Called when user touches sensitivity seek bar.
//( value ranges from 0 to 100 )
function skb_OnTouch( value )
{
 sensitivity
= value;
 
ChangeSettings();
}


//Called when user touches mosaic spinner.
function spin_OnTouch( item )
{
 mosaic
= item;
 
ChangeSettings();
}


//Change the motion detection settings.
function ChangeSettings()
{
 
var x=3, y=2;
 
if( mosaic=="3x3" ) { x = 3; y = 3; }
 
else if( mosaic=="5x5" ) { x = 5; y = 5; }
 
else if( mosaic=="10x10" ) { x = 10; y = 10; }
 
 cam
.MotionMosaic( x, y, (100-sensitivity)/5, minPeriod, img );
}


//Add messages to log.
function Log( msg )
{
 
var maxLines = txt.GetMaxLines()-1;
 
if( log.length >= maxLines ) log.shift();
 log
.push( msg + "\n" );
 txt
.SetText( log.join("") );
}




Dave

unread,
Apr 13, 2019, 8:07:42 AM4/13/19
to androi...@googlegroups.com
Here is a better version that stops the timer when you press the back button... or else it keeps going for ever and is hard to stop!


   
    app
.EnableBackKey( false );

}


//Start motion detection.
function StartDetection()
{
 
//Enable 3x3 matrix motion detection and mark
 
//motion detections in the image control.
 cam
.MotionMosaic( 3, 3, (100-sensitivity)/5, minPeriod );
 cam
.SetOnMotion( OnMotion );
 
 
//Create folder for saved pictures and
 
//set image size, counters etc.
 app
.MakeFolder( snapFolder );
 cam
.SetPictureSize( 1024, 768 );
 maxPics
= 10; count = 1;
 
 
//Create array to hold log messages.
 log
= new Array();
 
Log( "Ready" );
 
 
//Start preview.
 cam
.StartPreview();
}


//Called when the back key is pressed.
function OnBack()
{              
    app
.SetAlarm( "Cancel", 1234 );

John Calder

unread,
Apr 13, 2019, 10:50:46 PM4/13/19
to DroidScript
Hello Dave,

Thank you very much for taking an interest in this area.
I spent most of yesterday coding my version so this is well timed,
Some interesting techniques here that are new to me like app.SetAlarm.

My biggest advance today has been to start using the "pinned app" technique.
"cam" code that was running OK up until now, on encountering "Android 8 Go" for the first time freezes up under the lock screen.

I will now continue my story in more detail as I switch to joining the discussion:
"[Sample] Timed Security / Nature Camera"

Regards, John




Reply all
Reply to author
Forward
0 new messages