adb install < >
. If 2 or more devices are connected, we get:error: more than one device and emulator
- waiting for device -
adb -s <ID_device> installl < >
. To get the ID_device, you need to issue the adb devices
command, which will list the connected devices:List of devices attached
LGOTMS409c0d device
HT0BTHG02888 device
#!/bin/bash DEV_LIST=$(adb devices | awk '/device$/{if (NR!=1) {print $1}}') # , .apk DIR_PATH="/home/dn010891laa//" while [ -z "$DEV_LIST" ]; do zenity --question --title=" Android-" --text=" ?" --height=100 --width=400 if [ $? -eq "0" ]; then DEV_LIST=$(adb devices | awk '/device$/{if (NR!=1) {print $1}}') else notify-send "ADB" " " exit fi done path=$(find "$DIR_PATH" -name "*.apk*" | zenity --list --title " "$DIR_PATH"" --column " .apk" --height=370 --width=600) if [ $? -eq "1" ]; then exit fi if [ $(echo "$DEV_LIST" | wc -l) -ne "1" ] then DEV_NAME=$(zenity --list --title " ?" --column " " $(echo "$DEV_LIST" | xargs)) if [ $? -eq "1" ];then notify-send "ADB" " " exit fi else DEV_NAME="$DEV_LIST" fi adb -s "$DEV_NAME" install "$path" | tee /tmp/installlog.txt | zenity --progress --text " "$path" "$DEV_NAME"" --pulsate --auto-close --no-cancel log=$(cat /tmp/installlog.txt) zenity --info --title=" " --text="$log" rm /tmp/installlog.txt killall adb exit
zenity --help
in the terminalzenity --file-selection --title=" apk " --file-filter=*.apk
- then the "Select file "with the choice of any path and filter by file extension *. Apk. DEV_LIST=$(adb devices | awk '/device$/{if (NR!=1) {print $1}}')
- We get the output of the adb devices
command, delete the extra text from the lines, in this case the text “device”, and output all the lines except the first one, since it contains unnecessary text “List of devices attached” - this is all assigned to the DEV_LIST variable. while [ -z "$DEV_LIST" ]</code>: <code>-z
- returns true, if the length of the line is 0, I think that in the body of the loop, everything is clear. path=$(find "$DIR_PATH" -name "*.apk*" | zenity --list --title " "$DIR_PATH"" --column " .apk" --height=370 --width=600)
- we search for all files with the * .apk extension along the specified path, and output the result to the list via zenity - assign the selected path to the path variable if [ $(echo "$DEV_LIST" | wc -l) -ne "1" ]
- we read the list of devices, we get the number of lines, if there are more lines than 1, then we build the list: DEV_NAME=$(zenity --list --title " ?" --column " " $(echo "$DEV_LIST" | xargs))
, the selected value is assigned to DEV_NAME. adb -s "$DEV_NAME" install "$path" | tee /tmp/installlog.txt | zenity --progress --text " "$path" "$DEV_NAME"" --pulsate --auto-close --no-cancel
- we give the installation command, in parallel we write the installation progress in the log file, and we transfer the parameters to zenity --progress
- to display the progress zenity --progress
. then after the installation is complete, we read the information from the log and display a message about the installation result. It looks like this:Source: https://habr.com/ru/post/204160/
All Articles