Launch Android Emulator with No Data via Command Line - android

I'm trying to figure out how to launch an emulator with no data connection or airplane mode, either one will work. Im testing my application against data loss, however I need this to be atomized. Therefore I'm trying either to launch the emulator with no data via command line, or write bash script to launch emulator, turn data off, then run Unit Test.
RESOLVED - Per Recommendations
#! /usr/bin/expect
set timeout 10
spawn telnet localhost 5554
expect "OK"
send "gsm data off\n"
send "quit\n"

The quick and dirty way to do it could be to make an app that starts at boot and turns data off, then run the emulator and install the app. This does have potential for inconsistency however.
The other thing you can do to leave just the emulator without a network is to telnet into the emulator and turn data off. To automate it, I made a simple (and crude) example using a batch file and vbscript to feed telnet the commands since my work machine is running Windows.
The batch file:
#echo off
emulator -avd YOURAVDNAMEHERE
timeout /t 10
telnet_turn_data_off.vbs
telnet_turn_data_off.vbs:
set oShell=CreateObject("WScript.Shell")
oShell.Run "telnet localhost 5554", 9
WScript.sleep 500
oShell.Sendkeys "gsm data off{ENTER}"
WScript.sleep 500
oShell.Sendkeys "gsm voice off{ENTER}"
WScript.sleep 500
oShell.Sendkeys "quit{ENTER}"
WScript.sleep 500
oShell.Sendkeys "quit{ENTER}"
WScript.sleep 500
If running on Linux or Mac OS, expect should be able to script telnet (as seen by the edit to the question).
It is also worth noting that on older emulators (eg 2.2), turning data off might not do anything. My above example was tested with a 4.2 emulator and it appeared to cut off data properly.

I typically use physical hardware for testing instead of emulators, but if you can't find an option to enable airplane mode you could simply disconnect your computer from the internet before launching the emulator. No internet for your computer = no internet for your emulator.

Use This Following steps..
Go to Eclipse
Window->show view->other->android->Devices
now select your running emulator and Again
Go to,
Window->show view->other->android->Emulator Control
Now in that..set Data to Unregister from Home
From Device and Emulator
In Device or Emulator Go to,
Setting -> Wireless & networks -> Airplane Mode -> ok

Related

Android Studio - how to use my wifi in order to connect to internet

I searched on how to get an Internet connection from my emulator in Android Studio and it was suggested I start up the emulator from the command line as follows: emulator -avd Pixel_3a_XL_API_29 -dns-server 8.8.8.8. This indeed has provided an Internet connection when I do from the command line, after adb shell, then run-as com.example.myapplication, then ping abcnews.go.com. this returns packets from the server "...r.cloudfront.net". Looking up this server, it appears to be for Amazon AWS, and is "free", up to some data limit I haven't looked up yet. This is OK short-term, but I would prefer to use my home wifi rather than go thru a different server. What's the best way to have my Android Studio emulator be able to connect to the Internet via my home wifi? (do I need a plugin?) TIA, Steve
First of all, emulator below API 25 doesn't support wifi.
Second, you can't connect the emulator directly to your WiFi.
The WiFi in the emulator provides a virtual hotspot to which the emulator automatically connects.
So, best practice would be that you connect your PC to your home WiFi and then run the emulator on your PC.

Is there a way to build and run an Android Studio app on a phone remotely?

I am developing an app for Android that controls a robot using the FTC SDK, and I need to be able to make small changes to motor values in the code and re-install it to test the new code. My problem is that I need to do this a lot of times, and the system of taking the phone out of the mount (which takes a while) and plugging it into my computer to upload, waiting for it to upload, turning off the power to the robot, plugging the phone back in to the robot, and turning the power back on has started slowing our progress down a lot. I was wondering if there was any way I could install the new code on the phone without taking it out of the mount.
Our phone is connected to a usb hub with a webcam and the hardware controller, so I was wondering if attaching a wireless usb transmitter to the hub and my computer would still let the phone show up on the android studio connections manager and let me install it.
So if anyone has done this before, or knows about any way to make this work, thank you for the help!
Yes. First make sure that the robot phone has developer mode and USB debug enabled.
(Do this by going to settings -> software info and click on build number ten times, then go settings -> developer options and enable USB Debug)
Then, go into the robot controller phone and under the three dots at the top right select program and manage. Connect your computer to the shown internet name and password.
Next if you are on Windows plug in the phone and run the following code in command prompt,
pushd "%userprofile%\AppData\Local\Android\sdk\platform-tools"
adb disconnect
adb tcpip 5555
adb connect 192.168.49.1
popd
PAUSE
If you are on Mac plug in the device and run the following code in terminal,
cd ~/Library/Android/sdk/platform-tools
./adb disconnect
./adb tcpip 5555
./adb connect 192.168.49.1:5555
Finally, disconnect the phone, go back to android studio and happy wireless coding.

Android Emulator has no "network" command

I launch an AVD, it doesn't seem to matter which one but I have tried Nexus 4 and with API 18 and 25, and then connect via telnet to send commands. It connects fine, auth is fine, but then a command like "network speed edge" or "network speed full" results in:
KO: unknown command, try 'help'
Ok, fine I can look at the help, but there is no network-related command in the list of available commands:
help
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
Additionally, I'm running the newest Android Studio, completely updated, on Linux Mint 18.1. Other commands like "geo" and "power" work as expected.
The network command is not already neccesary because the android studio provides you a tool bar from where you can change the network type.
It was so easy for me to do it. this tool bar shows up next to the emulator screen.

What to do when the terminal displays "Sorry, could not find a PTY"? (Mac OSx)

I'm connecting an android device to an FTDI, which is connected to my Mac. On my android device I'm using FTDI AOA HyperTerm. I can send chars without any problem to my mac using this program: https://www.decisivetactics.com/products/serial/. As you can see I can only use it for 7 days, so I want to use my Terminal instead.
When I run this command:
screen /dev/tty.usbserial 9600
I get a blank screen with two messages, the second one being "Sorry, could not find a PTY".
What should I do to fix this?
EDIT: when I closed the Serial program, it worked on my Terminal. However, when I restart my Terminal it gives the same message.
I open Serial, select my USB device, close serial and use my Terminal.
Why is this?
I know this is old but I found the same problem today with my Raspberry PI and a PI UART card attached. I found that this error occurred when I opened up a screen session but didn't close it completely. I was able to fix by going to Activity Monitor and terminating any "screen" processes.
In my case there were no other "screen" processes running, but simply unplugging the device from the computer (i.e., USB to serial adapter) then plugging back in again cleared the issue.

Disconnect network in Android emulator while keeping ADB alive

I have made a mistake somewhere in my code that my Android app crashes when I switch off the network in the emulator while the app's HTTPClient is making some request.
But I cannot debug it, because when I switched off the network, I also lost the ADB connection. Thus I cannot see what exception is causing the crash.
I have tried switching off the network by:
F8
Set 'Data' to 'Unregistered' or 'Denied' in DDMS Emulator Control
I can put my Mac offline and ADB will stay up, but unfortunately I cannot reproduce the crash that way.
Is there a way to turn off network in the emulator, while keeping ADB alive? I basically need access to the LogCat entries.
Thanks!
You can run logcat from the device instead of from ADB and redirect it to a file for offline reading.
adb shell logcat [-v threadtime] > /sdcard/mylogs/logcat.log
Instead of
adb logcat [-v threadtime]
Then you can get the file when you reconnect to the device.
On linux this is pretty simple with iptables firewall. I suppose you trying to debug api calls so just block api host:
iptables -I OUTPUT -d api.example.com -j DROP
Sure you can do the same thing with Mac or Windows firewall.
You could always put the device into airplane mode, that will still allow you to connect over adb but not give the emulator a connection to the internet. You can also turn off data through eclipse via the emulator control section in ddms by putting in unregistered/denied to the data drop down.
I know this is old question but someone might use find for this.
My setup
Eclipse Kepler with emulated android 4.4
If you want to keep your adb alive and network turned off, you can try this.
Start emulated device
Activate flight/airplane mode
Restart Eclipse
It should work! Check DDMS perspective for attached devices or use adb devices command

Categories

Resources