How to access camera flash light?

285 views
Skip to first unread message

Durga Prasad

unread,
Jan 6, 2015, 10:55:25 AM1/6/15
to androi...@googlegroups.com
How to access camera flash light using Droidscript?

Any help appreciated.

Timo Octazid

unread,
Jan 6, 2015, 11:07:02 AM1/6/15
to androi...@googlegroups.com
Hi,
I dont know because I hav'nt played with it but try "cam.SetFlash("on");" or "cam.SetFlash("off");"

Many Greetings
Timo

Durga Prasad

unread,
Jan 6, 2015, 11:39:25 AM1/6/15
to androi...@googlegroups.com

Hi Tim,

Thanks for the reply. This is what i tried. But seems to be not working...


//Called when application is started. 
function OnStart() 
{    
    //Fix orientation to landscape since 
    //most phone's cameras work this way.    
    app.SetOrientation( "Landscape" ); 
       
    //Create horizontal layout that fills the screen. 
    lay = app.CreateLayout( "Linear", "Horizontal,FillXY,VCenter" ); 
    lay.SetBackground( "/res/drawable/pattern_carbon", "repeat" ); 
  
    //Create camera view control. 
    cam = app.CreateCameraView( 0.6, 0.8 );     
    cam.SetMargins( 0, 0, 0.04, 0 ); 
    lay.AddChild( cam );   
     
    //Create vertical layout on right for other stuff. 
    layRight = app.CreateLayout( "Linear", "Vertical" ); 
    lay.AddChild( layRight ); 

    //Create image control for previewing pictures. 
    img = app.CreateImage( null, 0.18, 0.22 );   
    img.SetBackColor( "#ff000000" ); 
    layRight.AddChild( img );       
     
    //Set target image for picture previews. 
    cam.SetPreviewImage( img ); 
     
    //Create shutter button. 
    btn = app.CreateButton( "Snap", 0.2, 0.15, "Alum" ); 
    btn.SetMargins( 0, 0.06, 0, 0 ); 
    btn.SetOnTouch( btn_OnTouch ); 
    layRight.AddChild( btn );  
     
    //Add main layout to app. 
    app.AddLayout( lay ); 
     
    //Create a folder for snaps. 
    snapFolder = "/sdcard/Snaps"; 
    app.MakeFolder( snapFolder ); 
     
    //Start preview after 1 second. 
cam.SetFlash("on");
    setTimeout( "cam.StartPreview()", 1000); 


//Handle shutter button. 
function btn_OnTouch() 

    //Take a picture and store to sdcard. 
//cam.Setflash("on");


 cam.TakePicture( snapFolder + "/Snap.jpg" ); 


   cam.SetFlash("off");
}

Selami Dinçer

unread,
Jan 6, 2015, 11:49:16 AM1/6/15
to androi...@googlegroups.com
https://play.google.com/store/apps/details?id=com.SeloSoft.flashl



My first app on googleplay .

cam.SetFlash(true ); 
cam.SetFlash(false ); 

Selami Dinçer

unread,
Jan 6, 2015, 11:52:38 AM1/6/15
to androi...@googlegroups.com

Working..
cam.SetFlash(true ); 
    setTimeout( "cam.StartPreview()", 1000);  
}  

//Handle shutter button.  
function btn_OnTouch()  
{  
    //Take a picture and store to sdcard.  
//cam.Setflash("on"); 


 cam.TakePicture( snapFolder + "/Snap.jpg" );  

cam.SetFlash(false ); 

Durga Prasad

unread,
Jan 6, 2015, 12:05:13 PM1/6/15
to androi...@googlegroups.com
Yes its working great. I tried your app. Its nice.

Thanks for the code!

Timo Octazid

unread,
Jan 6, 2015, 12:17:58 PM1/6/15
to androi...@googlegroups.com
Hi Selami,
I tried your app too but it would be better if you write in english too, I dont understand any word in your app :-) I think its a about box if I press the back button? And the text will be not displayed complete...
And why do you need wlan permission in your app?
Many Greetings
Timo

Selami Dinçer

unread,
Jan 6, 2015, 12:41:05 PM1/6/15
to androi...@googlegroups.com
Hi Timo.
FlashL app language Türkish.
I do not language editing.
Permission:
permisosin error or There are links on the googleplay.


FlashL app code this ;

function Sal_Link()
{
    app.OpenUrl( "https://play.google.com/store?hl=tr" );
}

Chris Hopkin

unread,
Jan 7, 2015, 8:52:54 AM1/7/15
to androi...@googlegroups.com
Hi Guys

Just a quick note about using the CameraView - it has a SetOnReady() function that you can use to pass a callback to be called when the camera is ready to be used:

cam = app.CreateCameraView( 0.6, 0.8 );

cam
.SetOnReady(OnCameraReady);

....

//Called when camera is ready.
function OnCameraReady()
{
    cam
.SetFlash(true);
    cam
.StartPreview();
}

Using this method means you shouldn't have to use a timeout to start the camera preview.

Thanks

Chris
Reply all
Reply to author
Forward
0 new messages