Is there a way to do the following instructions using Android on phone and Windows on computer?
Computer: Reads numbers and meeting-dates out of a database.
Computer: Connects to the smartphone (via USB?) and uses its "send SMS"-function
Smartphone: Sends SMS with given Text.
Or do i have to use Third Party Email to SMS tools? I'd like to avoid that.
You can use USB debugging and some faked user input.
First, enable USB debugging. Depending on your Android version and device model, this may be either an option somewhere in the normal settings app or in the hidden developer mode which you can access by tapping the build number under "Status" 7 times. Also, you may be asked to allow access from your computer the first time you try to do anything with this feature.
Then, download ADB and any driver needed for your device, if any. ADB is a command-line tool to send debugging commands to your device.
You can use adb devices in the console to see if things work - you should see your device listed.
The idea is now to start the SMS app with recipient and text already filled in (which is a supported action) and then fake the user clicking "Send". This is where the tricky part lies. Depending on your device, there can be different key input required than for mine, for example. Usually you will need to send one or more D-Pad presses plus "Enter" (yes this works even if the device doesn't have a D-Pad).
The commands you'll need:
adb shell am start -a android.intent.action.SENDTO -d sms:<full phone number here> --es sms_body "<SMS text here>" --ez exit_on_sent true
This will open the SMS app with the values already filled in. Replace <full phone number here> with the phone number, and <SMS text here> with your text. If you need to use quotes inside the text, you have to escape them like \".
adb shell input keyevent <id>
This will send a fake keypress. The possible IDs are listed here. Particularly interesting are:
19: D-Pad up
20: D-Pad down
21: D-Pad left
22: D-Pad right
23: D-Pad center
66: Enter
You will need to play with these. You probably need to send 22 or 20 to simulate a "right" or "down" press to focus the "Send" button followed by 23 or 66 to simulate a press on the D-Pad center or enter key to "click" the button.
So, for example, it could look like this:
adb shell am start -a android.intent.action.SENDTO -d sms:+436501234567 --es sms_body "This is a test" --ez exit_on_sent true
adb shell input keyevent 20
adb shell input keyevent 66
This would open the SMS app with the number +436501234567 and the text This is a test already filled in and then simulate the "down" key and the "enter" key.
Please give the whole thing some time. Add some delays (at least 1s) between each command.
Related
I'm trying to track devices, SIMs and airtime cards for test purposes. I have multiple devices plugged into a computer and since the recent update to Android 12, I am not able to get the device IMEI. The IMEI is basically the device's FCC-required serial number and can be obtained from the UI with relative ease, but how can I obtain it via ADB or in some automated method on multiple devices from multiple carriers and OEMs?
Prior to Android 12 FEB patch, I would use service call iphonesubinfo 1 or service call iphonesubinfo 4. But unfortunately after the update I receive back Result: Parcel(ffffffffc ffffffff 00000000 '................') whereas before I would receive a parcel containing the IMEI for processing via script.
Is there a way to get IMEI on Android 12+? I am trying to stay away from using an app. This is a simple thing, from a privileged user (adb shell). It seems like a basic necessity for tracking and logistics purposes.
This command works to obtain IMEI. It works by pressing the dialer key, then typing *#06#, then parsing the text on screen to find the IMEI Label and the next element which contains the actual IMEI. Finally it parses that element by removing all before text=" and all after ".
adb shell "imei=$(input keyevent KEYCODE_CALL;sleep 1;input text '*#06#'; uiautomator dump --compressed /dev/stdout|sed s/\>\<\/\\n/g|grep -A1 IMEI|tail -n1|sed -e 's/.*text=\"//' -e 's/\".*//'); echo ${imei}"
to get just the 16-digit IMEI without checksum, replace the final echo statement with echo ${imei:0:16}
I found a good solution for Samsung One UI
First, run the About menu
adb shell am start -a com.android.settings.ACTION_DEVICE_INFO_SETTINGS
Then dump the UI
adb shell uiautomator dump
View the dump file
adb shell cat /sdcard/window_dump.xml
The IMEI1 in the <node index="12" and IMEI 2 in <node index="13"
Setup
I'm on an Android 10 device and have an app (henceforth generator) that generates data it can copy to the device's clipboard (this involves swipes, taps, etc.). I need to do that repeatedly, as many times as possible (hundreds, thousands, whatever), and retrieve that data programmatically (presumably through a bash or perl script wrapped around adb commands).
Question
What would be some effective ways of achieving this?
Elaboration on what I've tried
I actually have a solution, I am just not sure it's the "best" one can do (whatever that means). generator is closed-source so I can't alter its behavior in any way, but I can repeatedly
start generator and/or switch focus to it with
adb shell monkey -p <generator-app> 1
mimic the tapping actions that produce the data and copy it to the clipboard with various
adb shell input tap x y
commands;
open/switch focus to the Termux terminal emulator (on the Android device):
adb shell monkey -p com.termux 1
access the clipboard via its Termux:API add-on, by running the termux-clipboard-get command in the termux terminal (again, on the Android device). I control this through adb with
adb shell input text 'termux-clipboard-get\>\>file-on-android-gadget.txt' && adb shell input keyevent 66
(keyevent 66 means ENTER, and the \>\> means append, >>, with escaped characters).
repeat the whole shebang.
This gives me many instances of the desired output in file-on-android-gadget.txt, saved locally on the phone (I'm OK retrieving it later, etc.).
Alternative routes?
What bothers me is the need to switch back and forth between two apps. I don't know that I have much choice over how I interact with generator, as it's closed-source and does not expose its internals, but perhaps one can do better at "the other end", i.e. when retrieving the clipboard data.
Newer Android APIs have locked down access to the clipboard, rendering it difficult to interact with programmatically, through adb. This SO thread points to a repo for a (Kotlin + gradle) app that sets the clipboard via a service runnable through adb, but my attempts to get the clipboard have been unsuccessful (i.e. getPrimaryClip() returns empty). I believe this is because, as per the docs:
getPrimaryClip
public ClipData getPrimaryClip ()
Returns the current primary clip on the clipboard. If the application
is not the default IME or does not have input focus this return null.
So there might just be no way around having to focus on a second app before the clipboard can be retrieved. But I have no experience programming apps, hence the question.
A further reference
During my peregrinations I found another repo for an Android app (Java + maven) that both gets and sets the clipboard. Same caveat though: as of Android 10, it needs to be in focus for the broadcast receiver to retrieve the clipboard data (other than that it works fine; I have it on my Android 10 device as we speak). So this would fare no better than my currently-working termux-based solution detailed above.
I am working with phone with Android 4.0.4 (I know, the old one)
Now I need to override limit of 100 sms send per hour (Below android 4.1 there should be limit 100 sms per hour. Since android 4.1 there is limit 30 sms per 30 minutes).
Since Android 4.2 it is possible via adb shell settings put global sms_outgoing_check_max_count.
But I have no idea how to do it on Android 4.0.4 without rooting because there is no "adb shell settings" command. Any idea?
P.S. I am not creating app. I need to override this limit ideally in android settings via adb or by using another app for this (if it exists)
You could do it by creating the application and overriding the SmsUsageMonitor:
com.android.internal.telephony.SmsUsageMonitor
It should basically work on any phone, without rooting it first.
Could you try to follow theses steps via ADB :
1.Open Command Terminal
2.Type in adb shell hit enter
3.Type in su hit enter
4.Type in sqlite3 /data/data/com.android.providers.settings/databases/settings.db hit enter
5.Type in INSERT INTO secure (name, value) VALUES('sms_outgoing_check_max_count’, 9999); hit enter
6.Type in INSERT INTO system (name, value) VALUES('sms_outgoing_check_max_count’, 9999); hit enter
7.Type in .exit hit enter (you should now see a hash tag again instead of sqlite>. If not conitune typing in .exit and hitting enter until you are)
8.Type in sqlite3 /data/data/com.google.android.gsf/databases/gservices.db
9.Type in INSERT INTO main (name, value) VALUES('sms_outgoing_check_max_count’, 9999); hit enter
10.Again exit back to where the command line has a hashtag
11.Type in reboot and hit enter.
I don't have a phone with Android 4.0.4, so i can't confirm that it will work
Happy testing !
you have to use abd command to open that restrictions here is the link for tutorial change sms limit
1.Go to the android platform tool directory
`(C:\Users\username\AppData\Local\Android\Sdk\platform-tools)``enter code here`
open command shell by using Shift+mouserightclick and enter this command
adb shell settings put global sms_outgoing_check_max_count 5
settings put global sms_outgoing_check_interval_ms 9000000
I am actually reducing the number so Android warns me if I have sent more than 5 SMS messages within 30(9000000) minutes. Change “5” to whatever number you want
What exactly do you want to acheive with over 100 SMS per hour?
I am sure there is a way more efficient way of sending your data for example through
a wireless network or mobile data. You would hardly manage to reach the data limits of
those networks.
Just saying ... try only to do it over SMS if there really is NO other way of sending it.
Good luck!
I am working on a application, it contain social share options. Whenever I tap on facebook it will open facebook app in the device with share view.
After that, I want to bring my application to foreground.
I tried pressing back button,
press_back_button()
it is unsuccessful.
Is there any way to bring application to foreground in Calabash-android?
You should be able to do it by sending keypresses and screen touches with ADB
adb shell input keyevent KEYCODE_APP_SWITCH to open the recent apps menu
adb shell input tap 300 300
Will send a tap event on the screen but you'll have to play around with the coordinates to get them in the right place.
EDIT:
I just tried on my phone with the following commands and can reopen the most recent app
adb shell input keyevent KEYCODE_APP_SWITCH
adb shell input tap 300 1700
Before trying these commands on your ruby code see if they work from the terminal (not irb).
The second command uses x and y coordinates that will be different depending on the size of the screen on your phone, 300 1700 works for me but you will need to try some different numbers to make it work for you.
To open the second most recent app, which I think is what you will need, I have to run adb shell input tap 300 700. You will need to play around with this and see what works for you.
FINAL EDIT: I've found a nicer way to do this that's not dependant on screen resolution.
adb shell input keyevent KEYCODE_APP_SWITCH
Then to find your app (you may need to send these multiple times to get it to work)
adb shell input keyevent KEYCODE_DPAD_UP
and/or
adb shell input keyevent KEYCODE_DPAD_DOWN
Then to select
adb shell input keyevent KEYCODE_ENTER
you need to run the system command, e.g.
system("adb shell input keyevent KEYCODE_APP_SWITCH”)
This willl open recent activities.
I have a large set of devices that I want to add google accounts to. The google accounts are already setup so I just want to add these existing accounts to the devices through a command line script.
There are two possible ways (Non-Root):
#1 Develop an app that implements the Account Manager and facilates the login process.
#2 Use a series of ADB commands to pass the input strings and stimulate the touch events.
ADB Command Example:
Start the native add account settings screen
ADB shell am start -a android.settings.ADD_ACCOUNT_SETTINGS \
-n com.android.settings/.accounts.AddAccountSettings
Select the absolute coordinates of the screen where the Google account is located. Each device has different screen sizes, so you have to figure out the exact position of your device. If you have multiple apps with login accounts they will also appear here. E.g., Microsoft Office, Reddit, and WhatsApp.
adb shell input tap X Y
Tips: You can enable the Show taps and Pointer location from
Developer Option. This will give you the precious location of the
touch input.
Set the desired input text
adb shell input text "account#gmail.com"
If you want select a keyboard event, pass the event code from the KeyEvent constants
adb shell input keyevent 66
Here, 66 is the event code of "KEYCODE_ENTER"
Repeat the input/touch process until you successfully login to the system.