I woule need a bunch of gps coordinates for test data. I thought about if it's possible to use adb shell for creating a quick shell script which generates a range of gps coordinates in a for loop.
But I still don't figured out how to start gps service in shell like gps fix in telnet.
Thanks for your help.
Regards
You could do the scripting outside the device. tellandroid is a recently-released Python utility that exposes Android Debug Console operations to your development computer's command line, so you can run:
tellandroid geo set [--host=<host>] [--port=<port>] [--] <lat> <long>
and such. Then, your loop would be on your development machine (e.g., as part of a test suite) rather than trying to do it on-device.
You can send gps coordinates directly from the eclipse IDE, change the perspective to DDMS.
Best regards
Related
I would like to be able to type commands on my development machine (macOS/zsh) and have them do things on my Android app. This will require custom code in my Android app. What I'm trying to do is something similar to automating certain settings, so that I don't have to navigate to the settings screen of my Android app manually. This is to help me save time while I'm developing my app.
How can I get started? I'd love to see some examples of this being done but have been having trouble finding them.
Are there any libraries that can help me with this?
Also, for bonus points, I'd love to be able to have some sort of autocomplete on my Mac command line. How might I build that?
There's a few ways to do this:
1)Just write a Linux app, move it to your device, set the executable bit, and run it from adb shell (adb shell opens up a shell on an attached device with debugging enabled).
2)If you really need to access the app while its running, you can send intents to your app via the shell via adb shell am <options> This allows you to send an intent to the system. Then just write a custom Activity, Service, or BroadcastReceiver to receive that Intent and act upon it.
How can I get GPS coordinates from an Android device via a terminal?
I've searched everywhere and all I've found is Java code for apps, but not a decent method by just using a plain shell. I'm not interested in passive geo-location that uses nearby cell towers and wifi endpoints, but a method that uses the built-in GPS on a device. Is this even possible? Oh and side question:
Is it possible to toggle GPS via a terminal when rooted without any user confirmation?
Edit:
I found a way to execute what I want properly. Using /system/bin/settings, I can toggle GPS itself without user confirmation. After that, I can run a binary I made with Android NDK, and using JNI I can request the users current location.
You can get latest GPS location using this adb command
adb shell dumpsys location
I try to change the network type from android emulator. From the official android documentation (https://developer.android.com/studio/run/emulator-commandline.html), i want to use network to change LTE/UMTS/GPRS network type. I create a new emulator from the last Android Studio 2.2 and connect with telnet. I run the help command (after authentication) and I get :
Android console command help:
help|h|? print a list of commands
crash crash the emulator instance
kill kill the emulator instance
quit|exit quit control session
redir manage port redirections
power power related commands
event simulate hardware events
avd control virtual device execution
finger manage emulator fingerprint
geo Geo-location commands
sms SMS related commands
cdma CDMA related commands
gsm GSM related commands
rotate rotate the screen by 90 degrees
I don't see network as explain in the documentation and when I try to run a network command, I get an error... Anybody have already met this issue ? Any idea how to solve it ?
Ok, seems to be delete in last versions of the emulator. I hope the android team will implement this feature soon.
https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=emulator%20network%20unknown&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened&groupby=&sort=-id%20-stars&id=204888
I've been looking for an answer or the past 3 days, and haven't yet found one that works. I'm trying to write an Android app that can be controlled from ADB with custom commands. Is there anyway I can send strings back an forth between an app and an ADB shell?
Thanks in advance, and sorry for my noob qustion.
Sure, there are several ways to do this.
You could use a unix domain socket, and open it from both the android app and from a command line executable you would build by abusing the ndk, push to a version-dependent location on the device (/data/local, /sqlite_stmt_journals, etc) and run. Edit: in more recent android versions there may not be such writable/executable directories. You may have to have the app itself write the executable out to its private directory and set global read and execute permissions on it. Further Edit: adb can forward unix sockets, too.
Same thing with an internet socket, only now you have the option of setting up an adb port forward (provided the android app is the 'server' end) so as to communicate from a process running on your development machine directly with the android app, without passing data through the adb shell. Unless declaring internet permission is objectionable (it should be less of a concern than letting your PC-side app "drive" adb) this is probably the method that would stick closest to "official" capabilities and have the least android version dependence. It also can be trivially adapted to communicating over wifi.
You could use a pair of fifos and write and read them with shell commands (for portability, create them in the app's private storage but make them world readable/writeable)
you may be able to play some games with a pty
you could I suppose use files as mailboxes
you can use the 'am' command to send Intents (useful at least to start up the android app, if a bit inefficient for the communication)
First,thank you for your attention to my question
I'm planning to design an Android GPS locating application
here are my difficulties and situations
(1)my computer hardware has been out of date for a long time and running an android emulator for debugging is really time-costing,thus i bought a real device(android cellphone) one week ago,in the aim of replacing emulator during debugging
(2)i know how to send location datas to an emulator via "DDMS/Emulator Control/Location Controls",but it is disabled for a real device
(3)i am programming indoor,thus using physical gps locating function is not acceptable(even if i turn on "a-gps")
(4)i have found another topic here: Android mock location on device?
however,i can't open the detail links,like "Andrews link"," http://dehuysser.appspot.com/blog/android-developer-shell-released"
I guess these web sites are forbidden by my country......
Here are my questions:
(A)i have found some codes of making mock loation datas ,but these codes can not activate "onLocationChanged" function
However, i wonder if there is a way to send locating datas from PC to real device via USB port(i'm in USB debugging mode), just like sending locations from DDMS to emulator?
(B)i've got the information that, it is possible to send "geo fix" command to emulator as well as to a real device, by "telnet localhost ", but how to check out the port number occupied by my real device?
i know that 5554 port is used for a emulator,but what about the real device?
i've tried to command "netstat" in terminal, but it's a shame to say that i don't know which port is for my android phone......
(C)If my (A)(B) question is not practical,then what's "settings/applications/development/allow mock location" used for?
Please help me, and thank you for your answer!
I have wrote an app exactly for this (this functionality is not available on phones by default) - it's open source and provides exactly the same interface as the emulator (telnet to :5554 and run "geo fix ..." or "geo nmea"): in app store MockGeoFix
The easiest way of using mock data is using the mock test location provider API. It's at the bottom of the documentation page. I've tried it out and location is received in the onLocationChanged callback. Here is some code that you can try out.
The port used by adb is usually 5037.