0

Problem Description

I am writing a simple Widget for Android Devices. When user press on the widget a Camera Flashlight must turn Off and On. My Widget works fine when I launch it on Sony Ericsson Arc, but when I try to launch Widget on Samsung NexusS or Samsung Galaxy SII it do nothing (doesn't work).


Researches

I google this issue and find some answers for it. Most of users suggest to use SurfaceView and really surface view with size 1 pixel really work if it is placed on activity, but it doesn't work in my case (Widget doesn't support SurfaceViw).

LED flashlight on Galaxy Nexus controllable by what API?

I found this article and it was very useful, but how can I use it in my case, in the case if I want turn on light from widget ? I know that I can't use Surface view in Widget View as it is not supported yet, any Ideas ?


Question

Please provide me some links, open source projects or articles or something that can be helpful on how I can turn light on/off from the widget on Nexus S One and Galaxy S II.

Is there any universal code for working with camera on different phones ? Any information will be helpful.

Maybe I need to use native library ?

Thanks.

Community
  • 1
  • 1
Viktor Apoyan
  • 10,655
  • 22
  • 85
  • 147

2 Answers2

1

There is no official android API allowing you to manipulate camera flash alone. You have to go via official camera API - and it does not formally define how to manipulate flash LED. YOu can set different modes, but camera software can ignore it at will.

So, if this works on sony it does not have to vork for other hardware. There could be (and most probably there are) some vendor specific undocumented APIs though.

Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
  • This is really helpful answer, but I come to it searching through the internet for last 4 days, but can you provide some links or some parts of code on how to do this for example on Nexus S One ? @Konstantin Pribluda – Viktor Apoyan Dec 14 '12 at 13:08
  • I do not have specific samples for it - never owned one. But usually you should query camera whether it supports torch mode of flash, activate it and start perview. Camera application if one of few areas where hardware provider can be distinct from others - so they use it fully ( HDR on N4 etc ) - but this means that there is only small subset of apis useable everywhere – Konstantin Pribluda Dec 17 '12 at 08:41
0

A bit late in response,however, the camera has to pass a surface on some devices in order to turn flash on. Given that surface view is not applicable, you need to implement a surface texture instead, available as of api 11