Share My Creation Torch Unlock (from a locked device)

Hi all,

Here is a simple app that allows to light a torch... Yet another torch ? Yes, but this one can be activated:
- with a single click on the power button
- even if the device is locked (pin, swipe or password)

Screenshot_2014-01-03-16-47-42.png Screenshot_2014-01-03-16-47-52.png

The trick is to use a combination of FLAG_TURN_SCREEN_ON and FLAG_SHOW_WHEN_LOCKED from a background service.
Then the service wakes up an activity based on the screen_on event and the value of accelerometer...

EDIT : I forgot to mention that the impact on the battery is neglectible as the accelerometer values are monitored only during a 2 seconds timer's time slot and then inhibited untill the screen has been switched OFF and ON again ...

As the file is just 100kB too big to be uploaded here, I join the link to the play store.
https://play.google.com/store/apps/details?id=com.aeropic.TorchUnlock

Many thanks to all the support I found on this forum...
Please, don't hezitate to give me any feedback !

Alain
 
Last edited:

ilan

Expert
Licensed User
Longtime User
hi

i tried you app and i get an error msg on tripple key press mode
the vertical works fine

the msg was: camera not ready...

tried again and it works

maybe you should use try..catch to avoid error msg like this


how did you catch the power press??
do you have a link were i can see the code?

thank you
 
Last edited:

aeropic

Active Member
Licensed User
Longtime User
HI,

Thanks for having tried this !

There should be no difference in behavior wrt the camera between vertical unlock or triple press one.
Both methods just start an activity based upon CameraEX class.
The error message "camera not ready" is probably coming from the camera initialization.
I've already got it once or twice but I cannot reproduce it systematically. I tried to introduce some robustness around this bad init in the latest versions I put on the play store.
Should you be interested to try it, here is the link:
https://play.google.com/store/apps/details?id=com.aeropic.TorchUnlock

In this version, I've added some ads... sorry ! (you can click on it. I've to repay the price of the B4A compiler :) !!!)


The code does not catch the power press (this is not achievable as far as I know under Android), at the opposite it senses the fact that the screen turns ON with a simple event :

B4X:
Sub Process_Globals
   Dim PE As PhoneEvents
end sub

Sub PE_ScreenON (Intent As Intent)
    'Log ("screen on")
    ' put your code here ...
End Sub

then according to the selected "wake up" method it checks the accelerometer values or the fact that the screen is turned OFF then back ON within a short period of time (managed by a timer)

Alain
 

ilan

Expert
Licensed User
Longtime User
thanx, learned something new :)

about the ads, i am not sure that its a good idea to put ads in such apps
because the only time the user will see the ad is if he wants to change the settings
and how much will he stay in this menu?!

so you should maybe improve the app add more functions

there are lots of torch apps in the market but always people looking for something new

--------------
5* from me ;)
 
Last edited:

aeropic

Active Member
Licensed User
Longtime User
Thanks for the 5 stars, I'm not sure it deserves that score ;-)

About the ads, this is something weird and unexpected but I'm starting to make money with my other application (camera unlock) and this one has even less ads visibility: only on the settings screen... I get around 80 new installs a day, around 450 people have kept this application in their phone, the ad banner is seen around 1000 to 2000 times a day, and around 100 people are clicking on the ad banner each day... Go figure why ?
But this means more than 1€ a day o_O

Torch unlock is starting very slowly and the ads income is just 1€ (by now, 15 days after having published it...)

I will not become rich with that, it was not the initial purpose, I just wanted to know all the mechanisms of the play store and the ads world, but I must admit this is really fun !!!

All this thanks to Erel's amazing work, and all the help found here in the forum. Incredible piece of software B4A ...
 

ilan

Expert
Licensed User
Longtime User
dont worry, i started make some money after about 7-8 month of developing
i hope you will do it faster :)
 

aeropic

Active Member
Licensed User
Longtime User
so you should maybe improve the app add more functions

Ilan, just for fun, I followed your advice and I added a morse message function in my torch which allows :
- to "send" morse messages like SOS
- to use it as a pattern programmable flasher (there is a loop option which combined for instance with a morse "T" gives a long period flasher, while with a morse "E" makes a short period flasher)

It's always at the same address:
https://play.google.com/store/apps/details?id=com.aeropic.TorchUnlock

Now, I should develop a morse decoder using the illumination sensor ;)

Bye
Alain
 

ilan

Expert
Licensed User
Longtime User
NICE!

i have an idea for your app (if you have nerves to invest time on it)

i will send it to you via Private MSG
 
Last edited:

ilan

Expert
Licensed User
Longtime User
hi alain

i am trying to too add an option to turn on the flashlight in my app
i tried with ACL and other libraries but its not working very well

how do you turn on the flash light??
 

aeropic

Active Member
Licensed User
Longtime User
Hi Ilan,

Just use cameraEX class with a code like this :
B4X:
' set the default flash mode
        Try
        Dim flashModes As List = camEx1.GetSupportedFlashModes
        If flashModes.IsInitialized = True Then
      
            Dim flash As String = flashModes.Get((flashModes.IndexOf(camEx1.GetFlashMode) + 1) Mod flashModes.Size)
            camEx1.SetFlashMode("torch")
            camEx1.CommitParameters
        End If
        Catch
            log("error")
        End Try

bye
Alain
 

Bassaidai

Member
Licensed User
Longtime User
Congrats Alain!

I was wondering about the .apk file size... I tried to setup a minimum b4a file using CameraEx. The smalles filesize I can come up after compilation is ~8,100kb. How did you achieve to use CameraEx AND keep the filesize at 752kb?

Cheers
Bass
 

ilan

Expert
Licensed User
Longtime User
seems like you got full HD pics or maybe some wav files in your project FILES folder

try to create a new project with only one button and you will see that the apk size will be very small
 

Bassaidai

Member
Licensed User
Longtime User
ohh.... ok, I see. I put all my .psd sourcefiles into /files also. I was under the impression the compiler will include only USED stuff from there. Thanks for the hint, much appreciated! File size is now down to 470k, excellent!
 

aeropic

Active Member
Licensed User
Longtime User
ohh.... ok, I see. I put all my .psd sourcefiles into /files also. I was under the impression the compiler will include only USED stuff from there. Thanks for the hint, much appreciated! File size is now down to 470k, excellent!
Yeap ! Nothing to add... keep the image files as small as possible ;-)
Thanks for the congratulations

Alain
 

Shadow&Max

Active Member
Licensed User
Longtime User
Do all phones return the same string codes for flash like "torch, on, off, auto"? I want to change an icon when each mode is reached and need to know if this is standardized as a feature in phones with a flash.
 

aeropic

Active Member
Licensed User
Longtime User
I am not sure it is standardized. Most probably yes for ON, OFF. For the other two (AUTO and TORCH), not all devices will support them.
I would advice a piece of code like this one:
B4X:
Try
        Dim flashModes As List = camEx1.GetSupportedFlashModes
        If flashModes.IsInitialized = True Then
      
            Dim flash As String = flashModes.Get((flashModes.IndexOf(camEx1.GetFlashMode) + 1) Mod flashModes.Size)
            camEx1.SetFlashMode("torch")   '<=============== before doing this, test here if "torch" is in the flashmodes list
            camEx1.CommitParameters
        End If
        Catch
            ToastMessageShow(Translate.GetTagText("err3"), False)
        End Try
 

aeropic

Active Member
Licensed User
Longtime User
Top