How to use Java Function in Tasker? - Tasker Tips & Tricks

Hello,
I'm using Sygic Navigation for Android. Now I'm trying to get some data out of Sygic to use in Tasker. For example I want to get my Estimated Time of Arrival (ETA) and save it as a variable in Tasker. Sygic offers a SDK, see "developers [dot] sygic [dot] com [slash] documentation.php?action=code_geteta" (sorry, first post, not allowed to post URLs), so I guess there are possibilities with Tasker....??
The thing is, I'm really new to programming and have no idea how to start / what to do with the Java possibilities in Tasker
Is there anyone who can help me "translate" the Java code below to some Java code that I can use in Tasker? Or is this not possible at all?
Code:
import com.sygic.sdk.remoteapi.Api;
import com.sygic.sdk.remoteapi.ApiNavigation;
import com.sygic.sdk.remoteapi.model.RouteInfo;
...
String strETA = "";
try {
RouteInfo info = ApiNavigation.getRouteInfo(false, 0);
RouteInfo.RouteInfoTime eta = info.getEstimatedTimeArrival();
strETA = String.valueOf(eta);
} catch (GeneralException e) {
Log.e("RouteInfo", "Error code:"+ e.getCode());
}
Thanks!
Vic

I would not go the SDK / Java route unless you have some Java programming skills already.
In your case, try to investigate Autonotification and AutoInput which are two very popular Tasker plugins.
You can find some similar examples (I actually do it with Maps) on the AutoApps forum.

It won't work at all in Tasker unless you write a completely new plugin. How can you use Sygic SDK in Tasker?? I don't think it's possible. If the information is in the notification you can use Notification Listener to get the notification in the task and read it. If it's only on the screen you can read it using the action "read screen" of TouchTask plugin.

Related

GPS NMEA data using intermediate driver

Hi all,
Windows mobile SDK 6 has a FAKEGPS program wich provides fake NMEA data to the GPS. This FAKEGPS reads NMEA data from a txt file. This is perfect for testing on a emulator. But now i want to provide FAKEGPS my own txt file with a recorded trail.
For this reason i want to write a little program for my diamond which records NMEA strings into a textfile. Is this possible using the intermediate driver, or should this be done communicating to the device directly? Can anyone provide some sample code?
Thank you in advance!
Solutionator said:
Hi all,
Windows mobile SDK 6 has a FAKEGPS program wich provides fake NMEA data to the GPS. This FAKEGPS reads NMEA data from a txt file. This is perfect for testing on a emulator. But now i want to provide FAKEGPS my own txt file with a recorded trail.
For this reason i want to write a little program for my diamond which records NMEA strings into a textfile. Is this possible using the intermediate driver, or should this be done communicating to the device directly? Can anyone provide some sample code?
Thank you in advance!
Click to expand...
Click to collapse
Code:
[DllImport("gpsapi.dll")]
static extern IntPtr GPSOpenDevice(IntPtr hNewLocationData, IntPtr hDeviceStateChange, string szDeviceName, int dwFlags);
[DllImport("gpsapi.dll")]
static extern int GPSCloseDevice(IntPtr hGPSDevice);
[DllImport("gpsapi.dll")]
static extern int GPSGetPosition(IntPtr hGPSDevice, IntPtr pGPSPosition, int dwMaximumAge, int dwFlags);
[DllImport("gpsapi.dll")]
static extern int GPSGetDeviceState(IntPtr pGPSDevice);
Thank you. I found this code also in the GPS example of the SDK.
But the GET_POSITION function on the driver does not return raw NMEA strings, it returns a struct wich is already formatted. What i would like is these raw strings:
$GPGGA,191938.767,4738.0173,N,12211.1873,W,1,06,1.4,33.4,M,-17.2,M,0.0,0000*72
$GPGLL,4738.0173,N,12211.1873,W,191938.767,A*2A
$GPGSA,A,3,08,27,10,28,13,19,,,,,,,2.6,1.4,2.3*3E
$GPRMC,191938.767,A,4738.0173,N,12211.1873,W,0.103296,21.60,291004,,*29
$GPGGA,191939.767,4738.0173,N,12211.1871,W,1,06,1.4,33.4,M,-17.2,M,0.0,0000*71
$GPGLL,4738.0173,N,12211.1871,W,191939.767,A*29
$GPGSA,A,3,08,27,10,28,13,19,,,,,,,2.6,1.4,2.3*3E
$GPGSV,3,1,9,8,71,307,43,27,78,59,41,3,21,47,0,10,26,283,32*72
$GPGSV,3,2,9,29,13,317,0,28,37,226,38,13,32,155,31,19,37,79,40*48
$GPGSV,3,3,9,134,0,0,0*46
$GPRMC,191939.767,A,4738.0173,N,12211.1871,W,0.097420,25.48,291004,,*23
The MSDN site on this topic tells me there are two ways for retriving data from the intermediate driver:
1) Accessing Parsed GPS Data - I believe this is part of the example you provided. See http://msdn.microsoft.com/en-us/library/bb202033.aspx
2) Accessing Raw GPS Data - I hope this makes it possible to read all strings in NMEA. See http://msdn.microsoft.com/en-us/library/bb202097.aspx and http://msdn.microsoft.com/en-us/library/bb202019.aspx
The problem is that i don't understand what they are doing in the second example. "Open a connection to the GPS Intermediate Driver multiplexer, by calling CreateFile" Like.... how, where,what?
I found an example which listens to the GPS directly, but i prefer the intermediate driver if possible.
you should check out
http://forum.xda-developers.com/showthread.php?t=394203
this project is using the intermediate driver which IS the solution you should be using.
Wauw. Great stuff. But RemoteTracker is still using intermediate driver option 1 (Accessing Parsed GPS Data).
Until I find out how I could manage to get option 2 to work (Accessing Raw GPS Data from the intermediate driver), I will extract some from the following code to get the full Raw NMEA string.
http://www.codeproject.com/KB/mobile/GpsTracerAppWMCE5.aspx
Sadly it is bypassing the intermediate driver, but hey, it works. For all other GPS actions i will use option 1 from the intermediate driver.

[GUIDE] Communication without a context object

Okay guys.
I have seen a lot of posts where people need to trigger an action inside their own app from the xposed class they hooked. Sometimes (quite often) there is no context object to obtain where we could usually send a broadcast or start a service or even maybe an activity from our own apps we wrote.
This guide will allow me to show you how this is possible without the use of a context object. I have used this myself in multiple modules and it works quite wonderfully. I am going to provide as much code as possible without being too specific, that is where you will need your own intuition to figure out some simple things.
Now for the guide
First, obviously, we need to create a new xposed module. That's another thread found here. For the duration of this guide, I am going to assume you have read that. If you have not, stop reading this, and click that link and go read that please Its fun!
Alright, our module has been created, all manifest declarations established all jars imported. Sweet.
Now we are looking at an empty class file that implements the IXPosedHookLoadPackage.
Next, we need to create a class that extends Service. You can either create a nested class inside the Xposed class, or, my personal choice, create an entirely new class inside your package. ***(Don't forget to add this service to your manifest!!!)
Next, we need to create a boot receiver that will start our newly created service when our device gets booted so its already up and running. (Google that if you don't know how to do that.) here is a great read on how to do this.
Now, go back to your service class (either nested or its own file) and create the "onCreate" method. (If not done already)
Inside the onCreate method of your service, we will need to create a file inside the apps files directory. You can do this in the constructor as well if you please. I have the code below showing how to create your new file.
Code:
@Override
public void onCreate() {
super.onCreate();
File myCommands = new File(this.getFilesDir(), "commands");
}
Yes its that
Now that we have our file object created, we need to actually create the file as follows:
Code:
if(!myCommands.exists()) { //Make sure the file doesn't already exist first.
try {
myCommands.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
However, there are some things we need to do to allow the xposed hooked method permissions to read them, which are simple and as follows.
Code:
myCommands.setReadable(true, false);
myCommands.setWritable(true, false);
We need to use the method "setReadable" and "setWriteable" to set the files permission. The first boolean argument sets the file writeable or readable, the second boolean argument restricts it to the owner only, which since we used false, means that everyone can read and write to this file.
So, now lets take a look at our entire onCreate method thus far:
Code:
@Override
public void onCreate() {
super.onCreate();
File myCommands = new File(this.getFilesDir(), "commands");
if(!myCommands.exists()) {
try {
myCommands.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
myCommands.setReadable(true, false);
myCommands.setWritable(true, false);
}
Pretty simple. Now, we need to actually do something with this file. This is where the magic begins to happen
After our file is created, we need to create what is called a FileObserver. The following code explains how to do that.
Code:
FileObserver myActionsObserver = new FileObserver(myCommands.getAbsolutePath()) {
@Override
public void onEvent(int event, String path) {
// This is where things are done. Every time you open, write to, close etc a file. This method is executed.
}
};
Now our file observer is created. However, it is doing nothing. As of now, it does not even listen for file changes. I want to further define what to do on a file change first before I start receiving the changes.
The "onEvent(int event, String path)" method is what we will be defining.
The "event" argument determines what type of event was acted upon the file. For a full explanation, click here. The "CONSTANTS" table shows the different types of events acted upon a file. For this guide, I will be using the constant "CLOSE_WRITE".
So inside the onEvent method we should have this:
Code:
@Override
public void onEvent(int event, String path) {
// This is where things are done. Every time you open, write to, close etc a file. This method is executed.
if(event == FileObserver.CLOSE_WRITE) {
//This is where we are notified that something has happened.
//This is where we can communicate from the xposed hooked method to our own app where we can do whatever we need to do :)
}
}
Now we are notified of the "CLOSE_WRITE" action onto our file. The next step would be to read the text file for our actual command. For instance, we need to start up an activity. So, for the instance of this guide, I will use the command "startActivity".
Once our "onEvent" method is executed and we see that its action was CLOSE_WRITE, we are going to read the file for the action. This is simple, I really don't feel like I should/have to go into this, but I will to make the guide full.
Here we are going to read the file, I am using a BufferedReader for this.
Code:
try {
BufferedReader br = new BufferedReader(new FileReader(myCommands));
String action = br.readLine();
br.close();
} catch(Exception e) {
e.printStackTrace();
}
Now we got a string object of the contents of the file to determine the necessary actions to take. Don't forget to change the myCommands file to final
Now that we have all that setup, we can finally start receiving actions for the file. We simply do this by calling the "startWatching" method of FileObserver as follows.
Code:
myActionsObserver.startWatching();
Now, whenever that file is written to, we will get notified of it in our service
So now that our service is setup, we need to setup our xposed hooked method to write to the file.
I am going to make something up that prolly doesn't exist in android source, but its just an example method that I am going to hook
The only thing to note when creating the file is that we need to hard code the file's path.
Code:
@Override
protected void afterHookedMethod(MethodHookParam param) {
boolean status = (Boolean)XposedHelpers.getObjectField(param.thisObject, "status");
if(status) {
File myCommand = new File(Environment.getDataDirectory() + <your package name here>, "commands");
FileWriter fw = new FileWriter(myCommands);
fw.write("startActivity");
fw.close();
}
Now we have written to our file and our service will receive the action.
That about sums it up You can also do the reverse, you can create a FileObserver inside your xposed hooked method, and use your own activity or service to write to it and then have the xposed hooked method do some actions regarding the command being written to the file.
Please hit thanks and donate if I helped you out! Don't hesitate to ask questions either!
Thanks!
need help
Hi I`m using your code and it`s work I seccessed to comunicate between the module and the FileObserver.
But my problem is that I want to activate some class or send a intent to activate some function from the FileObserver and I don`t find a way to do it.
Do you have any solution for me??
Thanks
doronmazor said:
Hi I`m using your code and it`s work I seccessed to comunicate between the module and the FileObserver.
But my problem is that I want to activate some class or send a intent to activate some function from the FileObserver and I don`t find a way to do it.
Do you have any solution for me??
Thanks
Click to expand...
Click to collapse
This method is beyond hackey. TBH, I'd be embarrassed to use it in my code.
If you want to communicate from Xposed to your main app, add a broadcast reciever and talk to it via intent and putextra. Provided you're not passing sensitive data, this works wonderfully.
digitalhigh said:
This method is beyond hackey. TBH, I'd be embarrassed to use it in my code.
If you want to communicate from Xposed to your main app, add a broadcast reciever and talk to it via intent and putextra. Provided you're not passing sensitive data, this works wonderfully.
Click to expand...
Click to collapse
lol
Why would you be embarrassed? This works perfectly when we have no context object in the class/method being hooked. If coded properly, it functions the exact same way as a broadcast receiver. Where is your solution to communicating without a context object? Not exactly sure why you think this method doesn't work...
elesbb said:
lol
Why would you be embarrassed? This works perfectly when we have no context object in the class/method being hooked. If coded properly, it functions the exact same way as a broadcast receiver. Where is your solution to communicating without a context object? Not exactly sure why you think this method doesn't work...
Click to expand...
Click to collapse
Look, not trying to be mean...it's just a very hacky solution. There are other ways to resolve the context of the class/method being hooked, and better ways to communicate between xposed and the apk code besides writing a file to the /data partition and then watching it. Sure, it works, but IMHO, it's...well...hacky.
digitalhigh said:
Look, not trying to be mean...it's just a very hacky solution. There are other ways to resolve the context of the class/method being hooked, and better ways to communicate between xposed and the apk code besides writing a file to the /data partition and then watching it. Sure, it works, but IMHO, it's...well...hacky.
Click to expand...
Click to collapse
I am not taking you as being mean. Not one bit. Just trying to expand my knowledge and better my code. You said there are other ways to resolve the context of the class/method being hooked, what are they? You said there are better ways to communicate between xposed and the apk code other than writing and listening to a file, well what are they? lol. I am asking so I can use them.
I have done ample research when I wrote this guide, and there were no other ways to communicate when you couldn't get a context object. I do know you can call other methods and such using xposed to get objects, but that in itself is also hacky. I really would like to know what other ways there are so I can use them instead of the current method. A lot of "helper" class files have issues where there is no context because its not needed. Say you have a class file labeled "MathHelper" and you want to hook the method "getFirstZero" and in that method the user wrote something simple like this:
Code:
private int firstZero(String address) {
int returnValue = address.indexOf("0");
return returnValue;
}
THIS IS JUST A POOR EXAMPLE.
You have no context object. And the class is huge. You want your app to, i don't know, show a notification and perform some task when the address is equal to some explicit value. There is no way of telling your app what the address is.
So what would you personally do to resolve this aside from simply creating a method inside the xposed class with the proper actions. I'm honestly curious.

[Q] Is it Possible to implement reciever on the module class?

I need to implement a broadcast reciever that will fill variables for the methods my module will hook up.
But every thing that I tried out didnt work.
I tried to implement the reciever in the module class:
public class LogginExtra extends BroadcastReceiver implements IXposedHookLoadPackage {
But it says ClassNotFound.
Tried to make something with sharedPreferences, but the XSharedPreferences doesnt reads the prefs.
And I dont know how to solve this, if someone can help me I need to update 2 variables at the Module class (IXposedHookLoadPackage) from a broadcast reciever.
thanks in advanced.
caioketo said:
I need to implement a broadcast reciever that will fill variables for the methods my module will hook up.
But every thing that I tried out didnt work.
I tried to implement the reciever in the module class:
public class LogginExtra extends BroadcastReceiver implements IXposedHookLoadPackage {
But it says ClassNotFound.
Tried to make something with sharedPreferences, but the XSharedPreferences doesnt reads the prefs.
And I dont know how to solve this, if someone can help me I need to update 2 variables at the Module class (IXposedHookLoadPackage) from a broadcast reciever.
thanks in advanced.
Click to expand...
Click to collapse
The key to the solution is to realize the core of the module (the Xposed hooks) is not an application in itself. Instead its code runs as part of another application or as part of an Android system component. This is why XSharedPreferences is called 'shared'.
It depends on what your module is doing and when/where/how the code of you module runs, which solution is best.
Note that using XSharedPreferences isn't the holy grail either, as this solution might stop working in Android "L", because of new SELinux rules (which could affect quite some modules).
M66B said:
The key to the solution is to realize the core of the module (the Xposed hooks) is not an application in itself. Instead its code runs as part of another application or as part of an Android system component. This is why XSharedPreferences is called 'shared'.
It depends on what your module is doing and when/where/how the code of you module runs, which solution is best.
Note that using XSharedPreferences isn't the holy grail either, as this solution might stop working in Android "L", because of new SELinux rules (which could affect quite some modules).
Click to expand...
Click to collapse
Basically my module hook an Intent method, but I need a way to pass for the module the package name that it should look, and the package Ill get in a broadcast reciever, so, how can I pass a simple String variable for the module?? I understand what you said but still no clue to how to pass a variable from a reciever to the module itself.
caioketo said:
Basically my module hook an Intent method, but I need a way to pass for the module the package name that it should look, and the package Ill get in a broadcast reciever, so, how can I pass a simple String variable for the module?? I understand what you said but still no clue to how to pass a variable from a reciever to the module itself.
Click to expand...
Click to collapse
You can hook Intents at different places, which makes a difference, since this could be either within an application or within an Android component. Hooking within an application makes this simpler, since you will probably be able to use the application context to communicate.
Basically you can use some form of shared storage to pass information (which is what XSharedPreferences does) or inter process calls. Example of IPCs are intents and services, both if which require a proper Context instance to work.
The bottom line is that you first need to understand from where to where you need to communicate.
I am aware that I am not very concrete about what to do. You could take a look at the implementation of XSharedPreferences, which isn't very difficult to understand, or how for example XPrivacy does this, which is more difficult to understand: https://github.com/M66B/XPrivacy (basically the PrivacyManager class is used to fetch settings from a service implemented in PrivacyService class and running within Android).
But what you said about the XSharedPreferences, that it could possible stop working on L, makes me not wanting to use it, so here is my hook code:
findAndHookMethod("android.os.Bundle", loadPackageParam.classLoader, "getString", String.class, new XC_MethodHook() {
@override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (getExtra(loadParam.packageName)) {
String key = (String) param.args[0];
String value = (String) param.getResult();
getExtrasToSend().putString(key, value);
}
}
});
Basically it will grab every call to getExtras, of all packages, and when it get called it should check if the package that called, is the one I'm looking for (from the reciever part), I got 2 ideas, first one I'm testing right now, is I get a class wich holds a static field and method to the packageName variable, and I'm calling it with: (String)XposedHelpers.callMethod(Util.class, "getPackageName", null);
probably wont work, and I was thinking about hooking the method of my own reciever to get the variable in the module class, and use as static variable there.
Any of these should work? Is there a better way to make it??
caioketo said:
But what you said about the XSharedPreferences, that it could possible stop working on L, makes me not wanting to use it, so here is my hook code:
findAndHookMethod("android.os.Bundle", loadPackageParam.classLoader, "getString", String.class, new XC_MethodHook() {
@override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (getExtra(loadParam.packageName)) {
String key = (String) param.args[0];
String value = (String) param.getResult();
getExtrasToSend().putString(key, value);
}
}
});
Basically it will grab every call to getExtras, of all packages, and when it get called it should check if the package that called, is the one I'm looking for (from the reciever part), I got 2 ideas, first one I'm testing right now, is I get a class wich holds a static field and method to the packageName variable, and I'm calling it with: (String)XposedHelpers.callMethod(Util.class, "getPackageName", null);
probably wont work, and I was thinking about hooking the method of my own reciever to get the variable in the module class, and use as static variable there.
Any of these should work? Is there a better way to make it??
Click to expand...
Click to collapse
Static variables probably won't work, since the settings holder and the settings user probably run in different process spaces. You need either some kind of shared storage or an IPC mechanism to communicate the settings.
Is it possible to use files for that? or database? Im really lost, never work with that yet, and seems that there isnt any explanations on google.
caioketo said:
Is it possible to use files for that? or database? Im really lost, never work with that yet, and seems that there isnt any explanations on google.
Click to expand...
Click to collapse
Shared preferences does use an XML file, so yes. A database is possible too, but you need to make sure both the settings manager and the hook do have access to it, same as with using (XML) files. You'll need to take care of locking too, since multiple process will access the file or database.
M66B said:
Shared preferences does use an XML file, so yes. A database is possible too, but you need to make sure both the settings manager and the hook do have access to it, same as with using (XML) files. You'll need to take care of locking too, since multiple process will access the file or database.
Click to expand...
Click to collapse
I have broadcast receivers in my settings activity and my xposed module so they can communicate with each other. You need to setup your receiver in the xposed side programatically:
Code:
Context context = (Context)XposedHelpers.getObjectField(param.thisObject, "mContext");
IntentFilter filter = new IntentFilter();
filter.addAction(XposedReceiver.RESET_ACTION);
filter.addAction(XposedReceiver.REFRESH_ACTION);
context.registerReceiver(mBroadcastReceiver, filter);
The problem is that I'm hooking the Intent class, and it dont have a context field for me to register the broadcast.
EDIT: I don't think Im being clear of what I need, I need to be able to set someway to send the package name to the module, I'll hook this methods:
findAndHookMethod("android.os.Bundle", loadPackageParam.classLoader, "getString", String.class, new XC_MethodHook() { @override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (loadParam.packageName.equals(PACKAGE_NAME_FROM_BROADCAST) {
String key = (String) param.args[0];
String value = (String) param.getResult();
getExtrasToSend().putString(key, value);
}
}
});
and I need to pass that PACKAGE_NAME_FROM_BROADCAST from a broadcast receiver, dont know the way to make it, tried static variables, xsharedpreferences, etc.
Cant get it working. and I dont know more what to try.
caioketo said:
The problem is that I'm hooking the Intent class, and it dont have a context field for me to register the broadcast.
EDIT: I don't think Im being clear of what I need, I need to be able to set someway to send the package name to the module, I'll hook this methods:
Code:
findAndHookMethod("android.os.Bundle", loadPackageParam.classLoader, "getString", String.class, new XC_MethodHook() {
@override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
if (getExtra(loadParam.packageName)) {
String key = (String) param.args[0];
String value = (String) param.getResult();
getExtrasToSend().putString(key, value);
}
}
});
and I need to pass that PACKAGE_NAME_FROM_BROADCAST from a broadcast receiver, dont know the way to make it, tried static variables, xsharedpreferences, etc.
Cant get it working. and I dont know more what to try.
Click to expand...
Click to collapse
First of all it is not a good idea to hook into android.os.Bundle, since this will impact the system performance significantly.
Moreover android.os.Bundle is used very frequently in applications and various Android components, meaning your hook will run in a variety of process spaces. Getting a Context in this Xposed hook will therefore often not be possible. If you really want to go this way, a service directly registered with the service manager is your only option, but my advice is to find another, less intrusive, way to do what you want.
Ok, the problem is that, my module needs to grabs all calls to "getExtras" ("getStringExtra", "getBooleanExtra", etc) to know all extras that the application will expect, than I'll pass it to AutoShare app, so you can customize and start an intent with all possible extras.
Is there any other way to grab the extras without hooking the Bundle or Intent? About the perform, its doing nothing if its without the right package, so will it still slow the performance???
Thanks for the repply.
caioketo said:
...
About the perform, its doing nothing if its without the right package, so will it still slow the performance???
Thanks for the repply.
Click to expand...
Click to collapse
A hook never does nothing, since there will always be code executed. The hook you are trying to use will be executed really a lot, so there will be significant performance problem.
The 'bundle' is a general 'message', which is used for a lot of things. You should find a way not to hook into the 'bundle', but into a higher level function.

[GUIDE][Difficulty: Advanced] Send an SMS with Address, Speed, and URL for a Map Pin

Your phone is lost, or you've got a relative who you're okay with sharing your location to. If you're driving, it's hard to give them an exact location, but thanks to the power of Tasker and a Javascriptlet, you can do that and more. With this task, you'll be able to automatically send an SMS with the current Address, current Speed that the phone is traveling, and a URL that drops a pin on the phone's location in Google Maps. Very helpful for easily finding a location! I would like to thank Redditor /u/popillol for figuring out the proper Javascriptlet to parse the Google Maps Geocoding API results.
Prerequisites
Secure Settings plugin if you are rooted and want to be able to automatically toggle location mode
Create a new Profile and select the Event context. Go to Phone and select Received Text. For the Type, leave it at Any and the Sender field blank. However for the Content field, choose a trigger phrase that you will share with your trusted relatives. This trigger phrase should be unique enough that there is no way it will trigger based off of any random text message.
Create a Task and name it 'Get Location.'
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Now, for the task itself. Be warned that this involves some Javascript, so be sure you copy/paste the functions in properly otherwise it might not work.
Variables --> Variable Set. Set Name to %from and To to %SMSRF. This gets the phone number that the text was sent from and puts it into a variable called %from.
(If Rooted) Plugin --> Secure Settings. Choose Location Mode/High Accuracy under System+ Actions.
Location --> Get Location. Set the source as Any.
Net --> HTTP Get. Under Serverort, put in the following URL to access the Google Maps Geocoding API:
Code:
maps.google.com/maps/api/geocode/json?latlng=%LOC&sensor=false
Set Mime Type as text/xml
Code --> Javascriptlet. For the code, add the following:
Code:
var locj = JSON.parse(global("%HTTPD"));
var spd = Number(global("%LOCSPD"))*2.23693629;
var lat = global("%LOC").split(",");
var lon = Math.abs(lat[1]);
lat = lat[0];
var latd = Math.floor(lat);
var latm = ( lat - latd )*60;
var lats = ( latm - Math.floor(latm) )*60;
latm = Math.floor(latm);
var lond = Math.floor(lon);
var lonm = ( lon - lond )*60;
var lons = ( lonm - Math.floor(lonm) )*60;
lonm = Math.floor(lonm);
lat = latd+"\°"+latm+"\'"+lats.toFixed(1)+"%22N";
lon = lond+"\°"+lonm+"\'"+lons.toFixed(1)+"%22W";
var url = "https://www.google.com/maps/place/"+lat+"+"+lon+"/@"+global("%LOC")+",14z";
if ( locj.results.length > 0 )
{
var short = locj.results[0].address_components[0].short_name;
if ( short.search(/[^\d-]/) == -1 )
short = "";
else
short = "("+short+") ";
var add = locj.results[0].formatted_address;
add = short+add.replace(", USA","");
}
Phone --> Send SMS. For the Number, put in %from. For the Message, put in the following:
Code:
%add
Speed ~ %spd mph
URL: %url
That's it! As mentioned in the Reddit thread for this, you can use AutoInput to automate turning on/off location services if you aren't rooted, but it's a bit of a messy implementation so I recommend just leaving location services on.
Maybe publish the script that can be downloaded and inserted from tasker. Thanks.
vizdak said:
Maybe publish the script that can be downloaded and inserted from tasker. Thanks.
Click to expand...
Click to collapse
I've attached the script in the post. Enjoy!
MishaalRahman said:
I've attached the script in the post. Enjoy!
Click to expand...
Click to collapse
Dropped pin is not accurate, its showing all blue area. Whats the problem?
Hi,
Just bought tasker and setted this up, seems like the url query is not working, any tips?
Also, putting that url in chrome gives me the following:
Code:
{
"results" : [],
"status" : "ZERO_RESULTS"
}
Regards.
MishaalRahman said:
Your phone is lost, or you've got a relative who you're okay with sharing your location to. If you're driving, it's hard to give them an exact location, but thanks to the power of Tasker and a Javascriptlet, you can do that and more. With this task, you'll be able to automatically send an SMS with the current Address, current Speed that the phone is traveling, and a URL that drops a pin on the phone's location in Google Maps. Very helpful for easily finding a location! I would like to thank Redditor /u/popillol for figuring out the proper Javascriptlet to parse the Google Maps Geocoding API results.
Prerequisites
Secure Settings plugin if you are rooted and want to be able to automatically toggle location mode
Create a new Profile and select the Event context. Go to Phone and select Received Text. For the Type, leave it at Any and the Sender field blank. However for the Content field, choose a trigger phrase that you will share with your trusted relatives. This trigger phrase should be unique enough that there is no way it will trigger based off of any random text message.
Create a Task and name it 'Get Location.'
Now, for the task itself. Be warned that this involves some Javascript, so be sure you copy/paste the functions in properly otherwise it might not work.
Variables --> Variable Set. Set Name to %from and To to %SMSRF. This gets the phone number that the text was sent from and puts it into a variable called %from.
(If Rooted) Plugin --> Secure Settings. Choose Location Mode/High Accuracy under System+ Actions.
Location --> Get Location. Set the source as Any.
Net --> HTTP Get. Under Serverort, put in the following URL to access the Google Maps Geocoding API:
Code:
maps.google.com/maps/api/geocode/json?latlng=%LOC&sensor=false
Set Mime Type as text/xml
Code --> Javascriptlet. For the code, add the following:
Code:
var locj = JSON.parse(global("%HTTPD"));
var spd = Number(global("%LOCSPD"))*2.23693629;
var lat = global("%LOC").split(",");
var lon = Math.abs(lat[1]);
lat = lat[0];
var latd = Math.floor(lat);
var latm = ( lat - latd )*60;
var lats = ( latm - Math.floor(latm) )*60;
latm = Math.floor(latm);
var lond = Math.floor(lon);
var lonm = ( lon - lond )*60;
var lons = ( lonm - Math.floor(lonm) )*60;
lonm = Math.floor(lonm);
lat = latd+"\°"+latm+"\'"+lats.toFixed(1)+"%22N";
lon = lond+"\°"+lonm+"\'"+lons.toFixed(1)+"%22W";
var url = "https://www.google.com/maps/place/"+lat+"+"+lon+"/@"+global("%LOC")+",14z";
if ( locj.results.length > 0 )
{
var short = locj.results[0].address_components[0].short_name;
if ( short.search(/[^\d-]/) == -1 )
short = "";
else
short = "("+short+") ";
var add = locj.results[0].formatted_address;
add = short+add.replace(", USA","");
}
Phone --> Send SMS. For the Number, put in %from. For the Message, put in the following:
Code:
%add
Speed ~ %spd mph
URL: %url
That's it! As mentioned in the Reddit thread for this, you can use AutoInput to automate turning on/off location services if you aren't rooted, but it's a bit of a messy implementation so I recommend just leaving location services on.
Click to expand...
Click to collapse
The part where you used +"%22N" and +"%22W" wouldn't it only make it work in the northern part of America?
Tried it out, and by my location I should be in Denmark, but the URL leads me to be somewhere in the Atlantic Ocean.
If I delete the two parts or simply change the W to an E, it works... But isn't it possible to make Google determine if it should be N/S and W/E? I mean, it can be fixed with an If(), but isn't there a way to make the api do that? But that's a cool script! I've been looking for ages for a function that could do the speed without root - you helped me out, thanks!
mnhs1010 said:
Dropped pin is not accurate, its showing all blue area. Whats the problem?
Click to expand...
Click to collapse
Sometimes, the URL that gets sent in the SMS doesn't format properly (there's nothing you can do about that except maybe use a URL shortener service) so you'll have to make sure you copy/paste the ENTIRE URL that gets sent rather than just clicking on what it gives you.
Cryorus said:
Hi,
Just bought tasker and setted this up, seems like the url query is not working, any tips?
Also, putting that url in chrome gives me the following:
Code:
{
"results" : [],
"status" : "ZERO_RESULTS"
}
Regards.
Click to expand...
Click to collapse
Hi, it's perhaps failing because your phone failed to get a location lock, meaning %LOC is not being set. If %LOC is not set, then the URL query will not work as Google Maps is expecting GPS coordinates being passed to it. As for why it doesn't work when you open the URL in Chrome, same reason.
One thing you can do is add an Alert --> Flash command and Flash %LOC right after the "Get Location" action. If you don't see GPS coordinates pop up then it means Tasker timed out on getting a location on you.
patrickpetersen said:
The part where you used +"%22N" and +"%22W" wouldn't it only make it work in the northern part of America?
Tried it out, and by my location I should be in Denmark, but the URL leads me to be somewhere in the Atlantic Ocean.
If I delete the two parts or simply change the W to an E, it works... But isn't it possible to make Google determine if it should be N/S and W/E? I mean, it can be fixed with an If(), but isn't there a way to make the api do that? But that's a cool script! I've been looking for ages for a function that could do the speed without root - you helped me out, thanks!
Click to expand...
Click to collapse
You are correct. To make the Javascriptlet work globally, you would need to do the following (this is from the Redditor that came up with the Javascript):
This assumes you're using North latitude numbers and West longitude numbers (so North America). If you want to use it globally, this would be the way to do it:
In the javascriptlet, check the sign (+ or -) of lon before getting the absolute value, and assign a new variable string with either W or E based on the sign. Do the same thing with lat (after the lat=lat[0] line) and with N or S. Then near the bottom where it puts the degrees, minutes, and seconds together, use that string variable after the "%22". I haven't tested it but that should work.
Click to expand...
Click to collapse
MishaalRahman said:
Sometimes, the URL that gets sent in the SMS doesn't format properly (there's nothing you can do about that except maybe use a URL shortener service) so you'll have to make sure you copy/paste the ENTIRE URL that gets sent rather than just clicking on what it gives you.
Hi, it's perhaps failing because your phone failed to get a location lock, meaning %LOC is not being set. If %LOC is not set, then the URL query will not work as Google Maps is expecting GPS coordinates being passed to it. As for why it doesn't work when you open the URL in Chrome, same reason.
One thing you can do is add an Alert --> Flash command and Flash %LOC right after the "Get Location" action. If you don't see GPS coordinates pop up then it means Tasker timed out on getting a location on you.
Click to expand...
Click to collapse
Thanks for the tip, it seems that step 3. Get Location takes a while (around a minute or more) to complete, after that, Flashing %LOC doesn't return anything.
Edit: Working now, I turned options for GPS to use Wifi and Bluethooth and it worked, but the link isn't sent completly, the hyperlink breaks at the first comma. Example: www.url.com/22w22s1234,etc.
Edit 2: Just read that there is nothing to do about it... gona find a way around.
Edit 3: Found a way around using the bitly API, the problem now is even if I change the location N to S (I'm in South America) it doesn't pin anything. (It doesnt even with N)
MishaalRahman said:
You are correct. To make the Javascriptlet work globally, you would need to do the following (this is from the Redditor that came up with the Javascript):
Click to expand...
Click to collapse
Can someone edit the script and provide me for global? I am in Pakistan and its not showing accurate drop pin.
This is the link it is giving me: https://www.google.com/maps/place/-34°32'48.6"S+70°37'12.2"W/@-33.4531551,-70.6200612,14z
No marker and the address is not accurate.
Edit: Address was not accurate because of where I was (office) went outside and it worked perfectly, still there is no pointer in the map.
MishaalRahman said:
Your phone is lost, or you've got a relative who you're okay with sharing your location to. If you're driving, it's hard to give them an exact location, but thanks to the power of Tasker and a Javascriptlet, you can do that and more. With this task, you'll be able to automatically send an SMS with the current Address, current Speed that the phone is traveling, and a URL that drops a pin on the phone's location in Google Maps. Very helpful for easily finding a location! I would like to thank Redditor /u/popillol for figuring out the proper Javascriptlet to parse the Google Maps Geocoding API results.
Prerequisites
Secure Settings plugin if you are rooted and want to be able to automatically toggle location mode
Create a new Profile and select the Event context. Go to Phone and select Received Text. For the Type, leave it at Any and the Sender field blank. However for the Content field, choose a trigger phrase that you will share with your trusted relatives. This trigger phrase should be unique enough that there is no way it will trigger based off of any random text message.
Create a Task and name it 'Get Location.'
Now, for the task itself. Be warned that this involves some Javascript, so be sure you copy/paste the functions in properly otherwise it might not work.
Variables --> Variable Set. Set Name to %from and To to %SMSRF. This gets the phone number that the text was sent from and puts it into a variable called %from.
(If Rooted) Plugin --> Secure Settings. Choose Location Mode/High Accuracy under System+ Actions.
Location --> Get Location. Set the source as Any.
Net --> HTTP Get. Under Serverort, put in the following URL to access the Google Maps Geocoding API:
Code:
maps.google.com/maps/api/geocode/json?latlng=%LOC&sensor=false
Set Mime Type as text/xml
Code --> Javascriptlet. For the code, add the following:
Code:
var locj = JSON.parse(global("%HTTPD"));
var spd = Number(global("%LOCSPD"))*2.23693629;
var lat = global("%LOC").split(",");
var lon = Math.abs(lat[1]);
lat = lat[0];
var latd = Math.floor(lat);
var latm = ( lat - latd )*60;
var lats = ( latm - Math.floor(latm) )*60;
latm = Math.floor(latm);
var lond = Math.floor(lon);
var lonm = ( lon - lond )*60;
var lons = ( lonm - Math.floor(lonm) )*60;
lonm = Math.floor(lonm);
lat = latd+"\°"+latm+"\'"+lats.toFixed(1)+"%22N";
lon = lond+"\°"+lonm+"\'"+lons.toFixed(1)+"%22W";
var url = "https://www.google.com/maps/place/"+lat+"+"+lon+"/@"+global("%LOC")+",14z";
if ( locj.results.length > 0 )
{
var short = locj.results[0].address_components[0].short_name;
if ( short.search(/[^\d-]/) == -1 )
short = "";
else
short = "("+short+") ";
var add = locj.results[0].formatted_address;
add = short+add.replace(", USA","");
}
Phone --> Send SMS. For the Number, put in %from. For the Message, put in the following:
Code:
%add
Speed ~ %spd mph
URL: %url
That's it! As mentioned in the Reddit thread for this, you can use AutoInput to automate turning on/off location services if you aren't rooted, but it's a bit of a messy implementation so I recommend just leaving location services on.
Click to expand...
Click to collapse
mnhs1010 said:
Can someone edit the script and provide me for global? I am in Pakistan and its not showing accurate drop pin.
Click to expand...
Click to collapse
Try to follow the instructions from the redditor or manually switch the 22N to 22S and 22W to 22E
patrickpetersen said:
Try to follow the instructions from the redditor or manually switch the 22N to 22S and 22W to 22E
Click to expand...
Click to collapse
its working fine 3 days but now it is sending the last same location always not new location.
Cryorus said:
Thanks for the tip, it seems that step 3. Get Location takes a while (around a minute or more) to complete, after that, Flashing %LOC doesn't return anything.
Edit: Working now, I turned options for GPS to use Wifi and Bluethooth and it worked, but the link isn't sent completly, the hyperlink breaks at the first comma. Example: www.url.com/22w22s1234,etc.
Edit 2: Just read that there is nothing to do about it... gona find a way around.
Edit 3: Found a way around using the bitly API, the problem now is even if I change the location N to S (I'm in South America) it doesn't pin anything. (It doesnt even with N)
Click to expand...
Click to collapse
I'm having this problem as well, the "Get Location" times out no matter how high I set the time out value to be. I've Turned on WiFi and Bluetooth scannaing to no avail. Whenever the task runs, I see the GPS icon show up in my status bar. And Google Maps has no problem getting my location quickly and accurately. I'm not sure what's going on
Ben Abel said:
I'm having this problem as well, the "Get Location" times out no matter how high I set the time out value to be. I've Turned on WiFi and Bluetooth scannaing to no avail. Whenever the task runs, I see the GPS icon show up in my status bar. And Google Maps has no problem getting my location quickly and accurately. I'm not sure what's going on
Click to expand...
Click to collapse
Did you test it outside? It takes a while to get my location here at my work, but outside it is super fast.
Cryorus said:
Did you test it outside? It takes a while to get my location here at my work, but outside it is super fast.
Click to expand...
Click to collapse
I just did, and it worked!
I don't know how Google Maps can get a lock on my so easily while I'm inside, but Tasker struggles, haha. Perhaps Google Services it's using Google Service's last known location of me.
It's simpler to use GeoTask in order to get the address and location.
Big Brother now works for me. Thanks, MishaalRahman.
One thing to point out for paranoid/right peoplle, it is possible to make an email-to-SMS gateway trigger it, although it does require setting up a new Context.
For those who do not know, a SMS gateway is when you send an email to a carrier's portal, and they pass the message along as an SMS. It also works backwards, sending an SMS back will send the reply to the sending email address. Wikipedia has a list of U.S. ones. For those outside the U.S., some research will be required, so go practice your Google-fu.
One thing to check for is the message may be wrapped in transit with things like the sender's name, subject line, etc. Test it out thoroughly, as the Context's contents must match the SMS exactly in order to trigger the Task. I recommend sending the message and simply copy/pasting what it spits out as the new Context's contents.
Last caveat, check to make sure that the message actually comes through the email reply, AT&T's SMS-to-email parser breaks on the degree symbol (Unicode B0 ALT+0176 °), so some editing may be required on the receiving end prior to presenting the URL to Gmaps. Once again, test thoroughly.
I don't know why, but I'm not able to import your projects into my tasker @MishaalRahman. Is there any way to export them in another format? Could you upload that? Is anyone else having this issue?
Would be awesome!
Cheers
I love the whole idea. It's great! Can you please write the Java scriptlet for me that works anywhere in the world? Requesting because I do not know coding at all.

Send data to multiple activities

Hello,
I am new to android studio and java in general. I was wondering If there is an easy way to send data from one activity to multiple activities.
On my first activity the user will enter some text. I want this text to be displayed on the second activity as well as on a summary page(my 6th activity).
I have figured out how to have the text go from activity 1 to the second activity. But I cannot figure out how to make it show up on the summary page as well. Anyone have any advise?
Thanks in advance!
NewtoStudio said:
Hello,
I am new to android studio and java in general. I was wondering If there is an easy way to send data from one activity to multiple activities.
On my first activity the user will enter some text. I want this text to be displayed on the second activity as well as on a summary page(my 6th activity).
I have figured out how to have the text go from activity 1 to the second activity. But I cannot figure out how to make it show up on the summary page as well. Anyone have any advise?
Thanks in advance!
Click to expand...
Click to collapse
You should use some permanent storage. In Android it's a lot ways to save the data: simple file, preferences, database, content providers and others.
I think for you case can be appropriate use the preferences. You need to write the preferences in one activity and read in another. Please see the following code example in Kotlin for details.
In order to write the preferences:
Code:
with(getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)) {
edit().putString(MY_MSG, "your message text").apply()
}
In order to Read preferences from destination activity:
Code:
with(getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)) {
mString = getString(MY_MSG,"");
}

Categories

Resources