Showing posts with label adb. Show all posts
Showing posts with label adb. Show all posts

android-adb


It is frustrating when you cannot connect to ADB.

Here is a list of troubleshooting items:

Developer Options - ADB

The first one is obviously enabling ADB in Settings > Developer Options

USB role


The USB role for ADB should be the "Device", your computer is the "Host".


  • Device
    • this device is powered by the USB
    • this device can send ADB data to the Host
  • Host Mode
    • this device powers the USB
    • this device sends and receives the data
  • Accesory - this device cannot be a "Host", but acts like one
    • this device powers the USB
    • this device sends and receives the data



Correct DATA USB cable (and hubs)


This one gets me the most often, once you verify that the USB cable works label it.
The same goes for any hub or USB C to USB A converter.



References




As an Amazon Associate I earn from qualifying purchases.

android-adb


It is frustrating when you cannot connect to ADB.

Here is a list of troubleshooting items:

Developer Options - ADB

The first one is obviously enabling ADB in Settings > Developer Options

USB role


The USB role for ADB should be the "Device", your computer is the "Host".


  • Device
    • this device is powered by the USB
    • this device can send ADB data to the Host
  • Host Mode
    • this device powers the USB
    • this device sends and receives the data
  • Accesory - this device cannot be a "Host", but acts like one
    • this device powers the USB
    • this device sends and receives the data



Correct DATA USB cable (and hubs)


This one gets me the most often, once you verify that the USB cable works label it.
The same goes for any hub or USB C to USB A converter.



References




As an Amazon Associate I earn from qualifying purchases.

Android screen size and dpi

Often, when working on particular device, you need to find out exact screen dimensions and dpi:


uki  08:04 ~ $ adb shell dumpsys window displays | grep dpi
    init=1440x2880 560dpi base=1440x2880 476dpi cur=1440x2880 app=1440x2737 rng=1440x1357-2737x2654



As an Amazon Associate I earn from qualifying purchases.

Android screen size and dpi

Often, when working on particular device, you need to find out exact screen dimensions and dpi:


uki  08:04 ~ $ adb shell dumpsys window displays | grep dpi
    init=1440x2880 560dpi base=1440x2880 476dpi cur=1440x2880 app=1440x2737 rng=1440x1357-2737x2654



As an Amazon Associate I earn from qualifying purchases.

Android: adb: filtering logcat

Usually I use IDE, but sometimes I have to create a very precise LOGCAT FILTER in terminal window.
Here is how I create a tag:
private static final String TAG = SomeActivity.class.getSimpleName();
 Log.d(TAG, "some description");
You could use getCannonicalName
Here I have following TAG filters:
  • any (*) View - VERBOSE
  • any (*) Activity - VERBOSE
  • any tag starting with Xyz(*) - ERROR
  • System.out - SILENT (since I am using Log in my own code)
Here what I type in terminal:
$  adb logcat *View:V *Activity:V Xyz*:E System.out:S

please +1 on stockoverflow:

http://stackoverflow.com/a/29307682/3566154









It takes time and effort to create tutorials, please support my efforts with a couple-dollar donation, any amount will be greatly appreciated and highly motivating!



As an Amazon Associate I earn from qualifying purchases.

Android: adb: filtering logcat

Usually I use IDE, but sometimes I have to create a very precise LOGCAT FILTER in terminal window.
Here is how I create a tag:
private static final String TAG = SomeActivity.class.getSimpleName();
Log.d(TAG, "some description");
You could use getCannonicalName
Here I have following TAG filters:
  • any (*) View - VERBOSE
  • any (*) Activity - VERBOSE
  • any tag starting with Xyz(*) - ERROR
  • System.out - SILENT (since I am using Log in my own code)
Here what I type in terminal:
$  adb logcat *View:V *Activity:V Xyz*:E System.out:S

please +1 on stockoverflow:

http://stackoverflow.com/a/29307682/3566154









It takes time and effort to create tutorials, please support my efforts with a couple-dollar donation, any amount will be greatly appreciated and highly motivating!



As an Amazon Associate I earn from qualifying purchases.

Android: ping server

When trying to connect from Android device to a given server sometimes you need to test if such connection exists:

1: Try from your computer is server is listening on IP_ADDRESS (192.168.x.xx) and given PORT (5xxx)


$ telnet 192.168.x.xx 5xxx

Trying 192.168.x.xx...

Connected to imx6qsabrelite.




2: From command line see if Android can ping the server:


$ adb shell ping 192.168.x.xx

PING 192.168.x.xx (192.168.x.xx) 56(84) bytes of data.

64 bytes from 192.168.x.xx: icmp_seq=1 ttl=64 time=2.65 ms



As an Amazon Associate I earn from qualifying purchases.

Android: ping server

When trying to connect from Android device to a given server sometimes you need to test if such connection exists:

1: Try from your computer is server is listening on IP_ADDRESS (192.168.x.xx) and given PORT (5xxx)


$ telnet 192.168.x.xx 5xxx

Trying 192.168.x.xx...

Connected to imx6qsabrelite.




2: From command line see if Android can ping the server:


$ adb shell ping 192.168.x.xx

PING 192.168.x.xx (192.168.x.xx) 56(84) bytes of data.

64 bytes from 192.168.x.xx: icmp_seq=1 ttl=64 time=2.65 ms



As an Amazon Associate I earn from qualifying purchases.

Android: ADB install apk

In this tutorial you will learn frequently used Terminal commands (from your computer) to manage APKs on your Android device.



As an Amazon Associate I earn from qualifying purchases.

Android: ADB install apk

In this tutorial you will learn frequently used Terminal commands (from your computer) to manage APKs on your Android device.


Search what APKs you have installed on your device

$ adb shell 'pm list packages -f' | grep /data/app/com.chicago
package:/data/app/com.chicagoandroid.cit299.week7.bookshelf-1.apk...
package:/data/app/com.chicagoandroid.cit299.naturesounds.appnaturesounds-1.apk...
package:/data/app/com.chicagoandroid.cit299.simplecamera-2.apk...

Uninstall APK by the package you found above.

$ adb uninstall com.your_package
$ adb uninstall com.chicagoandroid.cit299.week7.bookshelf

Success

Install APK 

in this example I am using created my Maven (mvn install), but you can use APK in the auto-generated build folder e.g.:

CIT299/appNatureSounds/build/outputs/apk/appNatureSounds-debug-unaligned.apk

$ adb install -r ~/.m2/repository/com/xyz.app_name/1.0-SNAPSHOT/app_name-x.y-SNAPSHOT.apk



Start the APK (you need to know the Activity name)


$ adb shell 'am start -n "com.your_package/com.your_packag.activity.YourMainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER'






As an Amazon Associate I earn from qualifying purchases.

Android: reinstalling several APKs from single folder

In this tutorial we will install multiple APKs from your local computer to Android device using ADB connection.

echo "                    ██╗"
echo "██╗   ██╗ ██╗   ██╗ ╚═╝"
echo "██║   ██║ ██╚═██╗═╝ ██╗"
echo "██║   ██║ ████══╝   ██║"
echo "██║   ██║ ██║╚██╗   ██║"
echo "████████║ ██║  ╚██╗ ██║"
echo "╚═══════╝  ╚╝   ╚═╝ ╚═╝"
echo

# Install new APKs
for apk in $(ls *.apk)
do
    echo "Installing $apk"
    echo
    adb install -r "$apk"
done



As an Amazon Associate I earn from qualifying purchases.

Android: reinstalling several APKs from single folder

In this tutorial we will install multiple APKs from your local computer to Android device using ADB connection.

echo "                    ██╗"
echo "██╗   ██╗ ██╗   ██╗ ╚═╝"
echo "██║   ██║ ██╚═██╗═╝ ██╗"
echo "██║   ██║ ████══╝   ██║"
echo "██║   ██║ ██║╚██╗   ██║"
echo "████████║ ██║  ╚██╗ ██║"
echo "╚═══════╝  ╚╝   ╚═╝ ╚═╝"
echo

# Install new APKs
for apk in $(ls *.apk)
do
    echo "Installing $apk"
    echo
    adb install -r "$apk"
done



As an Amazon Associate I earn from qualifying purchases.

ADB via USB on Samsung Galaxy Note 12.1 running KitKat

Many of you already know that, but since it is easy to forget here is a reminder how to turn ON the

"{}Developer options"

on devices running Android 4.4.x KitKat

Go to: Settings > General (tab) > About device

tap few times on "Build number" until the "{}Developer options" show in the left menu.



In "{}Developer options" 
- select USB debugging
I also often keep these 2 options selected when I share the device screen in demonstrations:
- Show touches
- Show pointer location
You can see the infinite sign I drew with my finger


For the screen sharing and capture I use command line software called "droid@screen"




As an Amazon Associate I earn from qualifying purchases.

ADB via USB on Samsung Galaxy Note 12.1 running KitKat

Many of you already know that, but since it is easy to forget here is a reminder how to turn ON the

"{}Developer options"

on devices running Android 4.4.x KitKat

Go to: Settings > General (tab) > About device

tap few times on "Build number" until the "{}Developer options" show in the left menu.



In "{}Developer options" 
- select USB debugging
I also often keep these 2 options selected when I share the device screen in demonstrations:
- Show touches
- Show pointer location
You can see the infinite sign I drew with my finger


For the screen sharing and capture I use command line software called "droid@screen"




As an Amazon Associate I earn from qualifying purchases.

Android: restarting app (APK) via adb

Often when you work with APK you need to restart it, it is much faster to create a Bash script for that:

echo '*** restart XYZ APK***'
echo 'Continue?'
read input
adb shell am force-stop com.xyz.package;
adb shell am start -n com.xyz.package/.SomeMainActivity


As an Amazon Associate I earn from qualifying purchases.

Android: restarting app (APK) via adb

Often when you work with APK you need to restart it, it is much faster to create a Bash script for that:

echo '*** restart XYZ APK***'
echo 'Continue?'
read input
adb shell am force-stop com.xyz.package;
adb shell am start -n com.xyz.package/.SomeMainActivity


As an Amazon Associate I earn from qualifying purchases.

Android: sending commands from computer

I found that often I have to send HOME, or BACK commands to my Android device.

KEYCODE_HOME
adb shell input keyevent 3

KEYCODE_BACK (you might have to execute it few times to get to HOME)
adb shell input keyevent 4

KEYCODE_CALL - opens the Call log
adb shell input keyevent 5

KEYCODE_ENDCALL - if not calling, same as pressing power button (you get choices: Power off, Airplane mode, Silent mode)
adb shell input keyevent 6


KEYCODE_VOLUME_UP - more noise
adb shell input keyevent 24

KEYCODE_POWER - same as pressing power button (you get choices: Power off, Airplane mode, Silent mode)
adb shell input keyevent 26


KEYCODE_CAMERA
adb shell input keyevent 27

KEYCODE_CLEAR
adb shell input keyevent 28


Full list of codes:

0  -  KEYCODE_UNKNOWN
1  -  KEYCODE_MENU
2  -  KEYCODE_SOFT_RIGHT
3  -  KEYCODE_HOME
4  -  KEYCODE_BACK
5  -  KEYCODE_CALL
6  -  KEYCODE_ENDCALL
7  -  KEYCODE_0
8  -  KEYCODE_1
9  -  KEYCODE_2
10  -  KEYCODE_3
11  -  KEYCODE_4
12  -  KEYCODE_5
13  -  KEYCODE_6
14  -  KEYCODE_7
15  -  KEYCODE_8
16  -  KEYCODE_9
17  -  KEYCODE_STAR
18  -  KEYCODE_POUND
19  -  KEYCODE_DPAD_UP
20  -  KEYCODE_DPAD_DOWN
21  -  KEYCODE_DPAD_LEFT
22  -  KEYCODE_DPAD_RIGHT
23  -  KEYCODE_DPAD_CENTER
24  -  KEYCODE_VOLUME_UP
25  -  KEYCODE_VOLUME_DOWN
26  -  KEYCODE_POWER
27  -  KEYCODE_CAMERA
28  -  KEYCODE_CLEAR
29  -  KEYCODE_A
30  -  KEYCODE_B
31  -  KEYCODE_C
32  -  KEYCODE_D
33  -  KEYCODE_E
34  -  KEYCODE_F
35  -  KEYCODE_G
36  -  KEYCODE_H
37  -  KEYCODE_I
38  -  KEYCODE_J
39  -  KEYCODE_K
40  -  KEYCODE_L
41  -  KEYCODE_M
42  -  KEYCODE_N
43  -  KEYCODE_O
44  -  KEYCODE_P
45  -  KEYCODE_Q
46  -  KEYCODE_R
47  -  KEYCODE_S
48  -  KEYCODE_T
49  -  KEYCODE_U
50  -  KEYCODE_V
51  -  KEYCODE_W
52  -  KEYCODE_X
53  -  KEYCODE_Y
54  -  KEYCODE_Z
55  -  KEYCODE_COMMA
56  -  KEYCODE_PERIOD
57  -  KEYCODE_ALT_LEFT
58  -  KEYCODE_ALT_RIGHT
59  -  KEYCODE_SHIFT_LEFT
60  -  KEYCODE_SHIFT_RIGHT
61  -  KEYCODE_TAB
62  -  KEYCODE_SPACE
63  -  KEYCODE_SYM
64  -  KEYCODE_EXPLORER
65  -  KEYCODE_ENVELOPE
66  -  KEYCODE_ENTER
67  -  KEYCODE_DEL
68  -  KEYCODE_GRAVE
69  -  KEYCODE_MINUS
70  -  KEYCODE_EQUALS
71  -  KEYCODE_LEFT_BRACKET
72  -  KEYCODE_RIGHT_BRACKET
73  -  KEYCODE_BACKSLASH
74  -  KEYCODE_SEMICOLON
75  -  KEYCODE_APOSTROPHE
76  -  KEYCODE_SLASH
77  -  KEYCODE_AT
78  -  KEYCODE_NUM
79  -  KEYCODE_HEADSETHOOK
80  -  KEYCODE_FOCUS
81  -  KEYCODE_PLUS
82  -  KEYCODE_MENU
83  -  KEYCODE_NOTIFICATION
84  -  KEYCODE_SEARCH
85  -  TAG_LAST_KEYCODE



As an Amazon Associate I earn from qualifying purchases.

Android: sending commands from computer

I found that often I have to send HOME, or BACK commands to my Android device.

KEYCODE_HOME
adb shell input keyevent 3

KEYCODE_BACK (you might have to execute it few times to get to HOME)
adb shell input keyevent 4

KEYCODE_CALL - opens the Call log
adb shell input keyevent 5

KEYCODE_ENDCALL - if not calling, same as pressing power button (you get choices: Power off, Airplane mode, Silent mode)
adb shell input keyevent 6


KEYCODE_VOLUME_UP - more noise
adb shell input keyevent 24

KEYCODE_POWER - same as pressing power button (you get choices: Power off, Airplane mode, Silent mode)
adb shell input keyevent 26


KEYCODE_CAMERA
adb shell input keyevent 27

KEYCODE_CLEAR
adb shell input keyevent 28


Full list of codes:

0  -  KEYCODE_UNKNOWN
1  -  KEYCODE_MENU
2  -  KEYCODE_SOFT_RIGHT
3  -  KEYCODE_HOME
4  -  KEYCODE_BACK
5  -  KEYCODE_CALL
6  -  KEYCODE_ENDCALL
7  -  KEYCODE_0
8  -  KEYCODE_1
9  -  KEYCODE_2
10  -  KEYCODE_3
11  -  KEYCODE_4
12  -  KEYCODE_5
13  -  KEYCODE_6
14  -  KEYCODE_7
15  -  KEYCODE_8
16  -  KEYCODE_9
17  -  KEYCODE_STAR
18  -  KEYCODE_POUND
19  -  KEYCODE_DPAD_UP
20  -  KEYCODE_DPAD_DOWN
21  -  KEYCODE_DPAD_LEFT
22  -  KEYCODE_DPAD_RIGHT
23  -  KEYCODE_DPAD_CENTER
24  -  KEYCODE_VOLUME_UP
25  -  KEYCODE_VOLUME_DOWN
26  -  KEYCODE_POWER
27  -  KEYCODE_CAMERA
28  -  KEYCODE_CLEAR
29  -  KEYCODE_A
30  -  KEYCODE_B
31  -  KEYCODE_C
32  -  KEYCODE_D
33  -  KEYCODE_E
34  -  KEYCODE_F
35  -  KEYCODE_G
36  -  KEYCODE_H
37  -  KEYCODE_I
38  -  KEYCODE_J
39  -  KEYCODE_K
40  -  KEYCODE_L
41  -  KEYCODE_M
42  -  KEYCODE_N
43  -  KEYCODE_O
44  -  KEYCODE_P
45  -  KEYCODE_Q
46  -  KEYCODE_R
47  -  KEYCODE_S
48  -  KEYCODE_T
49  -  KEYCODE_U
50  -  KEYCODE_V
51  -  KEYCODE_W
52  -  KEYCODE_X
53  -  KEYCODE_Y
54  -  KEYCODE_Z
55  -  KEYCODE_COMMA
56  -  KEYCODE_PERIOD
57  -  KEYCODE_ALT_LEFT
58  -  KEYCODE_ALT_RIGHT
59  -  KEYCODE_SHIFT_LEFT
60  -  KEYCODE_SHIFT_RIGHT
61  -  KEYCODE_TAB
62  -  KEYCODE_SPACE
63  -  KEYCODE_SYM
64  -  KEYCODE_EXPLORER
65  -  KEYCODE_ENVELOPE
66  -  KEYCODE_ENTER
67  -  KEYCODE_DEL
68  -  KEYCODE_GRAVE
69  -  KEYCODE_MINUS
70  -  KEYCODE_EQUALS
71  -  KEYCODE_LEFT_BRACKET
72  -  KEYCODE_RIGHT_BRACKET
73  -  KEYCODE_BACKSLASH
74  -  KEYCODE_SEMICOLON
75  -  KEYCODE_APOSTROPHE
76  -  KEYCODE_SLASH
77  -  KEYCODE_AT
78  -  KEYCODE_NUM
79  -  KEYCODE_HEADSETHOOK
80  -  KEYCODE_FOCUS
81  -  KEYCODE_PLUS
82  -  KEYCODE_MENU
83  -  KEYCODE_NOTIFICATION
84  -  KEYCODE_SEARCH
85  -  TAG_LAST_KEYCODE



As an Amazon Associate I earn from qualifying purchases.

Android: re-installing a bunch of apps with one script

I have a bunch (over a dozen) of APKs that go together on the device as a single solution, to remove them and reinstall all of them would be a time consuming effort, so I have scripts for that.

Do not believe "-r" option in "adb install -r", it does not always re-install the app.

I have a single script with bunch of uninstalls...

adb uninstall com.xyz.x1
$ adb uninstall com.xyz.x2
...
$ cd your_apks
# install all APKs in this folder
$ for i in *.apk; do adb install -r $i; done


As an Amazon Associate I earn from qualifying purchases.

Android: re-installing a bunch of apps with one script

I have a bunch (over a dozen) of APKs that go together on the device as a single solution, to remove them and reinstall all of them would be a time consuming effort, so I have scripts for that.

Do not believe "-r" option in "adb install -r", it does not always re-install the app.

I have a single script with bunch of uninstalls...

adb uninstall com.xyz.x1
$ adb uninstall com.xyz.x2
...
$ cd your_apks
# install all APKs in this folder
$ for i in *.apk; do adb install -r $i; done


As an Amazon Associate I earn from qualifying purchases.

apt quotation..