I'm developing a mobile web app where the content server is remote. I can do some basic testing on desktop Chrome with --disable-web-security option.
Is there a similar feature available on chrome on android? Or, any other browser on android?
UPDATE
I'm including these headers, Authorization, Access-Control-Allow-Origin, Access-Control-Allow-Credentials; but it seems to have no impact on the data server.
Am I missing any other settings?
The web app code resides on a local PC. Data on the remote hosts and the browser is on mobile in local LAN.
Actually, there is a way but it is a little hard, first, you should install adb on your system (Linux, Windows, macOS and etc) then restart adb server and at last plugin your Android device. check the adb connection with below command on your terminal/cmd:
$ adb list
When you see your device on the result of the above command, it is time to run the main command:
$ adb shell am start -n com.android.chrome/com.google.android.apps.chrome.Main
If the above command opens a Google Chrome tab or window, its time to disable security by your command order
Related
I use couple of Android apps on daily bases, and it's very time consuming.
I want to somehow automatize the process.
The idea is to install some sort of emulator on the server, and program that emulator through some programming language to run the apps on the server when its needed.
I'm a web developer, I work with PHP, nodejs, python,
not really familiar with mobile space.
Is there any solution out there to do what I want?
I search around and found Appium but I'm not sure if it would do what I want.
Please note these apps don't have a public 'api' for me to use.
Also I only have remote access to server via 'ssh terminal', so solutions with 'GUI' dependency wont work for me.
You can use some emulator, like Bluestacks and then run a script to run apps and then use macro tool to emulate clicks in the games or apps
check this link for the macro tool in bluestacks : https://www.bluestacks.com/blog/bluestacks-exclusives/combo-key-bluestacks-record-replay-action-single-key-en.html
Or you can write a script which uses adb commands to run and control the app.
For example.
to run apps. adb shell am start -n com.android.settings/.Settings
this command will open the settings app in the emulator.
to send touch events you can use : adb shell input touch <x> <Y>
adb shell input keyevent <keycode> to send keycodes
I'm assuming that you want to automate native Android apps.
Short answer: Appium will be good solution for you.
On your remote server you will need:
Android SDK and Simulator
Python 2.7 installed
Appium server/node (install using node.js npm )
With everything installed you will be able to start Appium Nodes on your server and run Appium scripts against them.
I suggest using CI server of choise for automating this process. It should make starting your test trough ssh terminal easier / 100% automated.
I never used Selenium/Appium in python, so I can't really help you with Appium tests code examples, but I'm sure there are a lot of basic tutorials for python.
You must install AppiumServer and android sdk/simulator in the remote server. I am going to show how it can be done in java. Hope you can convert it into javascript code.
Check the ip Address of your remote server using ipconfig
Start your appium server in the remote server
>appium -a "ip address of remote server" -p 4732 --session-override
Start the emulator in the remote server.
Define and initialize DesiredCapabilities and AppiumDriver in your code like following.
AppiumDriver<MobileElement> driver;
DesiredCapabilities caps= new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "android device");
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
caps.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 300);
caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
caps.setCapability("appPackage", "enter your appPackage");
caps.setCapability("appActivity", "enter your appActivity");
driver= new AndroidDriver<MobileElement>(new URL("remote server ip address" + ":4732/wd/hub"), caps);
Make sure both device are in the same network. you must get response while pinging to the remote server ip address
I have SSHDroid installed on my Android Device, and I've been investigating how to launch an app via SSH.
I can't seem to find any solution, nor documentation that explain why shouldn't I be able to do such thing.
How can I achieve to launch an app via SSH (computer to android) not using ADB? Is it even possible?
I'm doing it in this way:
ssh mymobile /su/bin/su -c am start -a android.intent.action.VIEW -d http://www.stackoverflow.com
su is run because it sets proper environment. Without it, the am fails.
I'm running openssh server on my mobile and login as root.
I am trying to reverse-forward port through ADB, but it just returns cryptic error of error: closed. Normal forwarding works. Session snippet:
$ adb forward tcp:59778 tcp:59778
$ adb forward --list
015d2109ce0c1a0f tcp:59778 tcp:59778
$ adb forward --remove-all
$ adb forward --list
$ adb reverse --list
error: closed
error: closed
$ adb reverse tcp:59778 tcp:59778
error: closed
error: closed
I am connecting via USB to non-rooted Nexus 7 2012 Android 4.4.4 from Windows 7 Pro x64 on Boot Camp.
adb reverse was introduced in Android 5.0
Since adb reverse is not supported in Android versions lower than 5.0, you need to use an alternative method, for example connecting via Wi-Fi instead. If you are using React Native, Facebook has added official documentation to connect to the development server via Wi-Fi. Quoting the instructions for MacOS, but they also have them for Linux and Windows:
Method 2: Connect via Wi-Fi
You can also connect to the development server over Wi-Fi. You'll first need to install the app on your device using a USB cable, but once that has been done you can debug wirelessly by following these instructions. You'll need your development machine's current IP address before proceeding.
You can find the IP address in System Preferences → Network.
Make sure your laptop and your phone are on the same Wi-Fi network.
Open your React Native app on your device.
You'll see a red screen with an error. This is OK. The following steps will fix that.
Open the in-app Developer menu.
Go to Dev Settings → Debug server host for device.
Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081).
Go back to the Developer menu and select Reload JS.
Follow these steps carefully.
Note: All commands need to run inside a project only.
Run this command first:
npm react-native start
Open another window in the same project and run:
curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
This will create index.android.bundle in the assets folder
Run:
npm react-native run-android
Now you can get apk in the build folder which will work fine.
adb reverse requires Android 5.0+. For devices previous to that, you'll need to use a workaround like so.
If you have busybox installed on your Android device (most Genymotion images do), you can emulate adb reverse using this incantation:
adb shell busybox nc -ll -p {guest port} -e busybox nc {host IP} {host port}
In this case, "guest" is the Android OS running in the emulator and "host" is the computer running the emulator.
cause of adb reverse isnt working on android prior 5 you could propably use adb forward with a service listening on android and tunneling other connections through this inbound connection. I am doing this mostly with ssh, but you would need an ssh server on android. you than can connect using ssh -R incommingreverseportonandroid:hostyouwanttoforwardto:portyouwanttoforwardto sshuseronandroid#localhost -p portyouhaveusedforadbforwaqrdtoaccessandroidssshserver
but i dont know how to enable an ssh server on android and maybe there is a better way cause ssh uses encryption which isnt needed over usb and using up cpu.
i am using this way with my server to share a service when i am forced behind a nat...
hope someone will find a way to bring this teoretical way into practical possibility
Just use 10.0.2.2 instead of localhost/127.0.0.1 for your hostname. It will directly try to connect to the port on the host machine (same affect as reverse).
I'm developing android set-top box app.
So, I have android box and its adb is REALLY SLOW.
When I have to install .apk file to debug my project, I use adb connect [ip address] via wifi and then build & run with Android Studio because the set-top box doesn't have USB port.
But it has serial port so I can connect its shell by screen /dev/tty.usb-serialblablabla 115200. when I use that command, I can see exactly same screen as one of adb shell.
Its adb shell(via wifi) shows very very slow performance.
For example, if I want to run pm list packages, I should type 'pm list packages' and wait for 2min.and then type enter key.(...sigh)
Whereas,Using screen /dev/tty.* methods respond promptly.
I don't know where this difference is come from.
but it is not matter of wifi. I checked its speed. it is quite normal.
In this circumstance, I click Run button in Android Studio after adb connect.
gradle build takes about 10sec.
upload .apk(10.2mb) takes about 10min (sigh).
Because screen ... way is much faster then adb connect way, I want push my .apk into device via 'screen'. how can I do? OR is there anything I can do to reduce time for putting .apk in android device?
You really should find out why adb transfers take so long. But if you insist on using serial console for uploads instead - you could just use any terminal application with XMODEM support on PC side to send the file and busybox rx -b <filename.apk> command on android side to save it. Then pm install <filename.apk> to install it.
I'm developing a simple app that connects to a webservice configured as a virtualhost in Apache, so its URL is myapp.localhost
In my development machine (Mac OS X) I can access it, and also from the iPhone emulator.
But I'm having problems from the Android emulator, it just cannot reach that URL, because it's not using my /etc/hosts file to resolve the "myapp.localhost" domain name.
Since I'm using Appcelerator Titanium (appcelerator.com), I cannot use "adb" to inject a custom hosts file to the Android emulator.
Is there a DNS server or something similar I can install in my Mac OS X system to translate that virtual host for the Android emulator?
I suppose you eventually found how to solve the problem. Still, I will give a possible answer for those who seek around, struggling with the same problem we had once.
Since android devices are emulated and not simulated (as opposed to iOS devices), they indeed have their own kernels, configuration files... and their own /system/etc/hosts. But you can actually use adb with Titanium. You just need to be careful. Since Titanium use a custom-generated virtual device, based on tiapp.xml, you will have to run your application at least once before the virtual device shows up in the device list.
If you have more than on virtual device you first need to get the name of the device generated by Titanium (typically emulator-XXXX).
adb devices
Then you can mount it and use adb push and pull commands to get the /system/etc/hosts out of the emulator's system, edit it and push it back. -s emulator-XXXX specifies on which device these commands are meant to be executed. If there is only one device, you can skip this option. See adb doc for more informations.
adb -s emulator-XXXX remount
adb -s emulator-XXXX pull /system/etc/hosts /whatever/directory/
You can now edit /whatever/directory/hosts with you favorite editor and add the necessary host. If you need to access the localhost interface of your development machine, 10.0.2.2 is a link to the computer's loopback interface. Simply add 10.0.2.2 myapp.localhost to the host and push it back to the virtual device.
adb -s emulator-XXXX push /whatever/directory/hosts /system/etc/hosts
Relaunch the simulator with Titanium and it should do the trick!