Ive tried so many ways to have the led flash light to turn on in one of my apps, but every code i try fails. Can any one please give me some type of example code?
I'm no programmer but I looked around in the Android API documentation and found this:
http://developer.android.com/reference/android/hardware/Camera.Parameters.html#FLASH_MODE_TORCH
And after 2minutes of googling I found this on the forum:
Code:
echo 125 > /sys/devices/platform/flashlight.0/leds/flashlight/brightness
From: http://forum.xda-developers.com/showpost.php?p=6305305&postcount=8
It's phone specific
Motorola you need to use some reflection like this:
http://code.google.com/p/droidled/s...com/droidled/demo/DroidLED.java?spec=svn2&r=2
HTC you can echo to the /sys/devices as patric.f mentioned
Nexus One/Galaxy S you can use FLASH_MODE_TORCH (also as patric.f mentioned)
Alternatively, if your app is focusing on something else and you don't want to deal with supported every device's flash light method, my TeslaLED app accepts service intents:
if you do a startService with an action of:
com.teslacoilsw.intent.FLASHLIGHT
You can attach a boolean extra with a key of "on", "off" or "toggle"
and a value of true to turn the flashlight on or off.
Strobe can be done by using an int extra of "strobe" followed by the
rate in Hz.
Related
***Requires Root*** (unless someone can show me a way that doesn't)
Checks the cell network type, NOT DATA TYPE.
Background: I am a truck driver for three months a year during my summer break from university. I love streaming music, but I love Nexus phones (and my $30 a month truly unlimited everything from T-Mobile!). Because I am on T-Mobile, my data connection on the interstates SUCK. So, I went ahead and got a prepaid Verizon mobile hotspot with the 10GB a month plan to use while on the road. However, I go through large cities frequently, so using the hotspot all the time is not ideal. I came up with the idea to use Tasker to track which mobile network type I am connected to, and turn off wifi when I gain HSPA or LTE, or turn wifi on when I lose HSPA or LTE. Sounds simple right? WRONG! The problem is that the only state context that Tasker has is Mobile Data, and can be set to 2G, 3G, 3G-HSPA, or 4G. I thought this would be enough, however, once wifi is connected, the mobile data state becomes None. So instead, I had to figure which string I needed from a dumpsys, output that string's value to a Tasker variable, and from there I could set If / Else statements. So let's begin:
First, I had to open up a terminal emulator and type in:
Code:
su
This will ask for Superuser access, simply allow always, and accept.
Next, type in:
Code:
dumpsys | grep DUMP
This will show you the different services you can view with dumpsys! Quite a bit of info there.
Now, from the helpful people over in the Tasker groups forum, I learned that network status is in
Code:
telephony.registry
So to only show that (instead of a huge long list of all the info), you will type in:
Code:
dumpsys telephony.registry
From here you can scroll through all the states. There will be a lot of values, but the one we are looking for is
Code:
mServiceState
In this case, I see it as (will vary between phone and provider):
Code:
mServiceState=0 home T-Mobile T-Mobile 310260 HSPA CSS not supported -1 -1 RoamInd=-1 DefRoamInd=-1 EmergOnly=False
"That's cool. Now what do I do with it?"
I'll tell you! With this info, head over to Tasker and make a profile (I used a time profile to activate every two minutes). After you make your profile, name a new task (I named it Celltype). Now add an activity, select Shell, then Run Shell. We've got some cool stuff here right? Yes, we do. It is a good idea to simply type in the command:
Code:
dumpsys telephony.registry | grep mServiceState | awk '{print}'
and set your timeout (mine is 4 seconds). Check the Use Root box, then in the Store Output In field, type a new variable name (I used %STATE); don't use a variable that is already in use! Dandy! Now just hit the back button and add another action. This time, select Alert and pick one (I picked popup, so that is what I am using in this guide).
Find the Text field, and enter your variable (%STATE) for me. Now just hit the back button, then hit the Play button in the lower left hand corner. You should get a Superuser request, allow it. Then, you should get a popup with the output of mServiceState, which for me is:
Code:
0 home T-Mobile T-Mobile 310260 HSPA CSS not supported -1 -1 RoamInd=-1 DefRoamInd=-1 EmergOnly=False
If you do not get a string like that, try changing '{print}' to '{print $0}' in the Command field in your Run Shell action.
Now find your network type. For me it is HSPA. Then count the position that network type text is in the mServiceState string. This is separated by spaces, so if I count mine, HSPA is in the sixth position (your's may vary). Did you notice I had you put at the end of the dumpsys in the Run Shell action:
Code:
awk | '{print]'
Well that prints out the result to whatever you tell Tasker to. You can do a lot of cool things with the print function, but I'm only going to cover what is relevant to this guide, which is the position identifier, $. In this case, since the text I want is in the sixth position, I will change the Command field in the Run Shell action to:
Code:
dumpsys telephone.registry | grep mServiceState | awk '{print $6}'
Your's may be in a different position, say it is in position three. Then you will put '{print $3}' at the end of your Command field. Again, make sure Use Root is checked and Store Output In has your created variable typed in.
Hit the back button to bring you to the main Task screen, and hit the play button in the lower left hand corner again. This time, in your popup, you should get the network type only. In my case, I got a popup that had the text, HSPA. If all goes well, and you do get ONLY the network type, then congrats! If you didn't, go back and make sure everything is correct (variable matches across actions).
If everything is dandy at this point, you can go ahead and delete the popup action (or keep it until you are all done with everything, like I did). What I did next is add a new action, selected Task and selected If. In the If action; type your created variable into the field on the left, then choose your matching method (mine is Matches) and type what you want it to match (or not match, etc) in the field on the right (for me, I typed HSDPA/HSPA/HSPA+/HSUPA/LTE, the / meaning OR).
After that, you can add whatever sub actions you want executed if your If statement is met. Once you have those done, you can add an Else action and any sub actions you want executed if your If statement is NOT met!
I have attached my XML from Tasker (just unzip, then import the XML), so you can go ahead and check out my whole project, break it apart and turn it into your own, whatever. If you share it, just please mention me. Or don't :crying:
P.S. If I missed anything, let me know! However, I AM a truck driver right now, I don't have very much time, but I will try to help if anyone needs it.
A truck-driving, college-studying, android-coder... Art Bell would be so proud.
:good:
Thanks, appreciate the tutorial. Interesting...
Thank you so much for this tips
It's very nice to improve my 2g/3g switching profile.
Here's what im using now:
Profile Name: Display On + 3g
Events: Display Unlocked + Not Wifi Connected ***
My task: 3g Enable
1 - Send Intent
Action
action.intellig.CHANGE_NETWORK_TYPE
Extra
extra.intellig.NETWORK_TYPE:0
2 - Flash
Text 3g
3 - Wait
1 minute
4 - Run Shell
Command
dumpsys telephony.registry | grep mServiceState | awk '{print $7}'
Use Root checked
Store Output In %STATE
5 - If
Condition
%STATE ~ GSM
6 - Send Intent
Action
action.intellig.CHANGE_NETWORK_TYPE
Extra
extra.intellig.NETWORK_TYPE:2
7 - Flash
Text 3g Forced
Hey.
Amazing share but im trying it doesnt work right now on lolipop i think.
Or i cant do it i dont know
Do you use this task right now?
This is a hacky fix but it is a fix.
It gives you a backlight that will go from dim to full bright without the need for any other apps running. It's not uber configurable like dedicated apps as it's limited by hardware but it requires 0 ram, 0 runtime and 0 battery
Append the following to hw_config.sh. The sleep is a hack but a viable one - hw_config is fired up by one of the rc files as a oneshot service so it should be OK to extend it's operation
If you prefer you could just make a standalone script with everything after the sleep command (make sure you have the dev= assignment from hw_setup too!) and fire it off with a script executer of your choice
Code:
#this sleep ensures that the system is up and done [email protected] with light levels before setup
sleep 30
#select als group for backlight
echo 1 > $dev/leds/lcd-backlight1/als_group
echo 1 > $dev/leds/lcd-backlight2/als_group
#set both to max. brightness - als will lower
echo 255 > $dev/leds/lcd-backlight1/brightness
echo 255 > $dev/leds/lcd-backlight2/brightness
#set custom als curve
echo 7,1,48,72,24,255,0 > $dev/als_group1
#set custom filter frequency
echo 1000 > $dev/als_filter_down_speed_mHz
echo 1000 > $dev/als_filter_up_speed_mHz
#turn on hardware als
echo 1 > $dev/als_on
Notes
Make sure you have completely uninstalled any other light controllers - Velis in particular wreaks havoc even when disabled - it still receives the screen on intent and resets the brightness which results in a black display - guess how I know ....
Make sure you have disabled auto brightness control in the standard Sony settings and set the slider to full bright for good measure
I use nobootanimation so my phone boots a bit quicker than some. It might be that sleep 30 isn't long enough for an animated startup
Best thing is probably to create a setup script and run that to satisfy yourself the hack works. Then add it to hw_config and increase the delay if it doesn't work!
If you want to know more about the als setup check HERE or read the AS3677 datasheet.
Sadly I wasn't able to find out how the ALS curves are loaded into the current system, hence the direct hardware poking
There's some useful debug capability built into the sysfs
cat $dev/debug to see light sensor outputs and calculated backlight settings
cat als_group1 to read back the curve settings complete with a graph showing the response curve
A software guy could probably easily make an apk that hooked to the SCREEN_ON intent to program all this (and have a nice gui to show/edit the curve) but I'm a hardware engineer so that ain't me!
It's easier to just use Lux. Thanks anyway.
pakatsui said:
It's easier to just use Lux. Thanks anyway.
Click to expand...
Click to collapse
LUX, YAB or other brightness app will don`t work correct on all my Xperias. Only with "system brightness settings" active in the background this apps will change the brightness in realtime. When i close the systemsettings brightness will change no longer or with some luck once when unlocking.
so i will test this Hack, hope it helps to become a wide range in realtime.
heross said:
LUX, YAB or other brightness app will don`t work correct on all my Xperias. Only with "system brightness settings" active in the background this apps will change the brightness in realtime. When i close the systemsettings brightness will change no longer or with some luck once when unlocking.
so i will test this Hack, hope it helps to become a wide range in realtime.
Click to expand...
Click to collapse
Lux works fine. I'm using it now.
Sent from my Xperia SP using xda premium
Hello t_o_f,
today i have made test this fix in Car navigation from sunlight to the moon. awesome. this is the best fix i have always seen for xperia autobrightness. :good::laugh::good: ten points from germany.
the best, lowest brightness it is configurable with the Stock slider!
Call me daft. I disabled auto brightness, jacked the brightness to high, and have no other brightness apps installed. I appended the above to /etc/hw_config.sh and rebooted.
auto brightness didn't work. It was still jacked up to high so I enabled it and tested, still not working. Did I do something wrong? I'm on 254 rooted.
I've been searching for an API for discovering in Java code whether the device has a notification light or not, and I've found nothing. So my simple question is: does such a thing exist? I'm working on an app that has some settings for notification light behavior, and I'd like to hide those setting options entirely on devices that don't have the hardware.
Indeed no way to do this.
But you can try the follow
When the user opens the app for the first time in on create make this
Try{
//open or use LED
Set visibility of LED options to True
}
catch {
//if not found, Set Option Visibility To False
}
Thought I would create a thread to discuss Tasker automation on the Z1C (help requests, troubleshooting, automation ideas, etc.)
First a help request:
Has anyone been successful in getting AutoInput or Sendevent shell commands (double taps, swipes) to work on the Z1C?
I've used this script in the past to record events and replicate them to create macros using Tasker shell, but the Z1C input devices (touchscreen, buttons) don't seem to be allowing capture using getevent:
http://forum.xda-developers.com/showthread.php?t=2233865
wernyuen said:
Thought I would create a thread to discuss Tasker automation on the Z1C (help requests, troubleshooting, automation ideas, etc.)
First a help request:
Has anyone been successful in getting AutoInput or Sendevent shell commands (double taps, swipes) to work on the Z1C?
I've used this script in the past to record events and replicate them to create macros using Tasker shell, but the Z1C input devices (touchscreen, buttons) don't seem to be allowing capture using getevent:
http://forum.xda-developers.com/showthread.php?t=2233865
Click to expand...
Click to collapse
Edit: always execute as root!!!!
task Swipe:
Script
execute Shell
input swipe x1 y1 x2 y2 speed
like:
input swipe 310 870 310 320 200
keyevents:
http://developer.android.com/reference/android/view/KeyEvent.html
like
power on/off
input keyevent 26 or
input keyevent KEYCODE_POWER
pause between actions:
sleep 1
sleep 2 etc.
tap:
input tap x y
start app:
am start -n app.name.name/ManifestActivity
close app:
am force-stop app.name.name
complete action screen on, unlock, start spotify, autoplay, screen off
am start -n com.spotify.music/.MainActivity;
sleep 2;
input keyevent 26;
sleep 1;
input swipe 310 870 310 320 200;
sleep 1;
input keyevent 126;
sleep 1;
input keyevent 26;
i hope it help
Maetz3 said:
Edit: always execute as root!!!!
task Swipe:
Script
execute Shell
input swipe x1 y1 x2 y2 speed
like:
input swipe 310 870 310 320 200
keyevents:
http://developer.android.com/reference/android/view/KeyEvent.html
like
power on/off
input keyevent 26 or
input keyevent KEYCODE_POWER
pause between actions:
sleep 1
sleep 2 etc.
tap:
input tap x y
start app:
am start -n app.name.name/ManifestActivity
close app:
am force-stop app.name.name
complete action screen on, unlock, start spotify, autoplay, screen off
am start -n com.spotify.music/.MainActivity;
sleep 2;
input keyevent 26;
sleep 1;
input swipe 310 870 310 320 200;
sleep 1;
input keyevent 126;
sleep 1;
input keyevent 26;
i hope it help
Click to expand...
Click to collapse
thanks! very helpful.
what about multi-touch or pinch-to-zoom? have not been able to find solutions that have bridged that online
double tap also seems to be a challenge for the Z1C, somehow even without sleep in between two "input taps" it is still too slow to be recognized as a double tap
wernyuen said:
thanks! very helpful.
what about multi-touch or pinch-to-zoom? have not been able to find solutions that have bridged that online
double tap also seems to be a challenge for the Z1C, somehow even without sleep in between two "input taps" it is still too slow to be recognized as a double tap
Click to expand...
Click to collapse
i dont know but i think you need something like nova launcher
i think you can combine this controls in tasker
for zoom you can use:
KEYCODE_ZOOM_IN (input keyevent 168)
KEYCODE_ZOOM_OUT (input keyevent 169)
Maetz3 said:
i dont know but i think you need something like nova launcher
i think you can combine this controls in tasker
for zoom you can use:
KEYCODE_ZOOM_IN (input keyevent 168)
KEYCODE_ZOOM_OUT (input keyevent 169)
Click to expand...
Click to collapse
Thanks ... tried the ZOOM_IN/OUT keyevents, but I think that is for the camera, I'm trying to implement this on Google Maps and Maps Engine, since they removed the Zoom and Scaling buttons on the official Google apps it's been a pain (and driving hazard) to manually zoom in and out with touchscreen input. (trying to map the zoom actions to my media controls on the steering wheel)
Hi all,
Let me start with an apology as I am not sure that I am in the right thread here, however tasker automation does seem to have alot of threads - I am confident that someone who knows more than me might be able to answer my questions/problems.
I am currently trying to automate a search in youtube using autovoice and autoinput. Via voice command so far I can get autoinput to launch youtube, and click the search bar, however I cant get it to input any text into the search bar! - So I really need to know, how to get autoinput to input variable text and search for it within youtube, not even sure which function of autoinput it would be to be honest.
Still learning.
Any help you can give would be fantastic,
Cheers
Dan
If what you want to achieve is to search YouTube, there are easier ways:
1. Simply ask Google Now to search or YouTube using the "watch" or "listen" command; or
2. Use an intent in Tasker to activate YouTube search with the search term %avcommnofilter (rather than try to use autoinput)
If you really must use autoinput, you can use the UI query action to find the right variable name for the search box, then use the 'autoinput action' action to paste your search term (%avcommnofilter) into the search box
dan34321 said:
Hi all,
Let me start with an apology as I am not sure that I am in the right thread here, however tasker automation does seem to have alot of threads - I am confident that someone who knows more than me might be able to answer my questions/problems.
I am currently trying to automate a search in youtube using autovoice and autoinput. Via voice command so far I can get autoinput to launch youtube, and click the search bar, however I cant get it to input any text into the search bar! - So I really need to know, how to get autoinput to input variable text and search for it within youtube, not even sure which function of autoinput it would be to be honest.
Still learning.
Any help you can give would be fantastic,
Cheers
Dan
Click to expand...
Click to collapse
I have a slightly different question how to make a script turning stamina mode on and off? It would be usefull because stamina sometimes prevents alarm apps from ringing in time.
so, I was googling around a bit, a few days ago, and found out you can control the torch (and other leds) from the command line, or a bash script.
Prerequisites
root (magisk or superSU)
FX file manager or Termux
Text editor
Instructions
Create a file in a directory of your choice with a '.sh' extension
Add the following code to the file:
Code:
su -c 'echo 255 > /sys/class/leds/torch/brightness'
Run the shell script in termux (cd to the directory and run it) or run it using FX, it will ask for root access if you haven't already granted it
Your torch is now on!
To turn it off create another file with
Code:
su -c 'echo 0 > /sys/class/leds/torch/brightness'
in it
Tested on an Honor 9 and P10+
If you have dual tone flash, yo may find different values cause either led to come on, for me, '255' is the yellow flash and '1' is the white flash
For a bit more messing around, cd to the '/sys/class/leds' directory, you will see a few more directories for other LEDs on your device, controlling them is exactly the same as the torch!
Works for me, thanks a bunch dude
EDIT: on honor 7x/Huawei mate se
Thank you so much for this but I found in my own experience, and from comments I saw where this has been shared, that a bash script perhaps wasn't the most effective to have to run each time so I thought of implementing this to Tasker, create a "pseudo toggle" and allocate it to a quick setting tile. The algorithm is:
Code:
If flashlightStatus = TRUE then
Run shell command: su -c 'echo 0 /sys/class/leds/torch/brightness'
Set variable flashlightStatus to FALSE
Else
Run shell command: su -c 'echo 3 /sys/class/leds/torch/brightness'
Set variable flashlightStatus to TRUE
End If
I set it up this way because if you've never set the variable before (or if it clears on reboot or something) then it won't equal true and would still enable. Also, when I set the brightness to 255 the torch had a slight yellow tint so upon further reading, despite that 255 should be full brightness, apparently max brightness is 3 and is a white light (this seems to disable automatically after around 750ms however). Hope this will help those who are still without a torch on treble GSIs.
P.S. I also set up a quick profile that if the flashlight status variable = true then to wait 750ms and check if still true then change to false and turn off the torch; this would reset to compensate for the OS turning the torch off automatically but Tasker still thinking it was on. I'm not sure how necessary this is or whether it's overkill or not.
beejkitsune said:
Thank you so much for this but I found in my own experience, and from comments I saw where this has been shared, that a bash script perhaps wasn't the most effective to have to run each time so I thought of implementing this to Tasker, create a "pseudo toggle" and allocate it to a quick setting tile. The algorithm is:
Code:
If flashlightStatus = TRUE then
Run shell command: su -c 'echo 0 /sys/class/leds/torch/brightness'
Set variable flashlightStatus to FALSE
Else
Run shell command: su -c 'echo 3 /sys/class/leds/torch/brightness'
Set variable flashlightStatus to TRUE
End If
I set it up this way because if you've never set the variable before (or if it clears on reboot or something) then it won't equal true and would still enable. Also, when I set the brightness to 255 the torch had a slight yellow tint so upon further reading, despite that 255 should be full brightness, apparently max brightness is 3 and is a white light (this seems to disable automatically after around 750ms however). Hope this will help those who are still without a torch on treble GSIs.
P.S. I also set up a quick profile that if the flashlight status variable = true then to wait 750ms and check if still true then change to false and turn off the torch; this would reset to compensate for the OS turning the torch off automatically but Tasker still thinking it was on. I'm not sure how necessary this is or whether it's overkill or not.
Click to expand...
Click to collapse
mind if i improve this?
Code:
su -c 'if grep -q 1 /sys/class/leds/torch/brightness; then echo 0 > /sys/class/leds/torch/brightness; else echo 1 > /sys/class/leds/torch/brightness; fi'
-- obviously you can change the 1 to whatever you want
that is the code i'm using, prevents the use of an unnecessary variable, so is faster, and will use less resources, plus its pretty much fail safe, since it reads the current state of the torch to determine if its on or off, so if something else sets it to a state it still works, if something else set you variable externally then the torch becomes messed up until a reboot.
plus, im assuming that variable is a tasker thing? not everyone will use tasker, so eliminating the variable all together makes it work on any app that can add custom quick settings tiles
ambitiousButRubbish said:
mind if i improve this?
Code:
su -c 'if grep -q 1 /sys/class/leds/torch/brightness; then echo 0 > /sys/class/leds/torch/brightness; else echo 1 > /sys/class/leds/torch/brightness; fi'
-- obviously you can change the 1 to whatever you want
that is the code i'm using, prevents the use of an unnecessary variable, so is faster, and will use less resources, plus its pretty much fail safe, since it reads the current state of the torch to determine if its on or off, so if something else sets it to a state it still works, if something else set you variable externally then the torch becomes messed up until a reboot.
plus, im assuming that variable is a tasker thing? not everyone will use tasker, so eliminating the variable all together makes it work on any app that can add custom quick settings tiles
Click to expand...
Click to collapse
Yes, the variable is a Tasker thing so I'm glad there is a solution that wouldn't rely on it. Thanks for the upgrade and I've already switched out my Tasker profile for this. Doesn't seem any quicker or anything but more simple!