Getting started with AndroidLayoutsGradle for AndroidRecyclerView onClickListenersNavigationViewIntentJSON in Android with org.jsonAndroid StudioResourcesData Binding LibraryExceptionsGetting Calculated View DimensionsAsyncTaskSharedPreferencesEmulatorMaterial DesignLint WarningsServiceStoring Files in Internal & External StorageWebViewProject SDK versionsRecyclerViewGoogle Maps API v2 for AndroidPorterDuff Mode9-Patch ImagesAndroid NDKRecyclerView DecorationsCamera 2 APIViewPagerCardViewHttpURLConnectionSQLiteADB (Android Debug Bridge)ButterKnifeSupporting Screens With Different Resolutions, SizesGlideRetrofit2DialogACRAGreenDAOFormatting StringsNotificationsAlarmManagerFragmentsHandlerCreating Custom ViewsBroadcastReceiverActivitySnackbarRuntime Permissions in API-23 +Logging and using LogcatVectorDrawable and AnimatedVectorDrawableTools AttributesToastInterfacesAnimatorsLocationTheme, Style, AttributeThe Manifest FileParcelableMediaPlayerMultidex and the Dex Method LimitData Synchronization with Sync AdapterMenuInstant Run in Android StudioPicassoBluetooth and Bluetooth LE APIRoboGuiceMemory LeaksUniversal Image LoaderVolleyWidgetsDate and Time PickersIntegrate Google Sign InIn-app BillingFloatingActionButtonContentProviderDagger 2RealmUnit testing in Android with JUnitAndroid VersionsWi-Fi ConnectionsSensorManagerLocalization with resources in AndroidProgressBarCustom FontsVibrationGoogle Awareness APIsText to Speech(TTS)UI LifecycleSpinnerData Encryption/DecryptionTesting UI with EspressoWriting UI tests - AndroidGreenRobot EventBusOkHttpEnhancing Android Performance Using Icon FontsHandling Deep LinksCanvas drawing using SurfaceViewFirebaseCrash Reporting ToolsCheck Internet ConnectivityFacebook SDK for AndroidUnzip File in AndroidAndroid Places APICreating your own libraries for Android applicationsGsonDevice Display MetricsTextViewListViewBuilding Backwards Compatible AppsLoaderProGuard - Obfuscating and Shrinking your codeDetect Shake Event in AndroidTypedef Annotations: @IntDef, @StringDefCapturing ScreenshotsMVP ArchitectureOrientation ChangesXposedSecurityPackageManagerImageViewGesture DetectionDoze ModeAndroid Sound and MediaSearchViewCamera and GalleryCallback URLTwitter APIsDrawablesColorsConstraintLayoutRenderScriptFrescoSwipe to RefreshAutoCompleteTextViewInstalling apps with ADBIntentServiceAdMobImplicit IntentsPublish to Play StoreFirebase Realtime DataBaseImage CompressionEmail ValidationKeyboardButtonTextInputLayoutBottom SheetsCoordinatorLayout and BehaviorsEditTextAndroid Paypal Gateway IntegrationFirebase App IndexingFirebase Crash ReportingDisplaying Google AdsAndroid Vk SdkLocalized Date/Time in AndroidCount Down TimerBarcode and QR code readingOtto Event BusTransitionDrawablePort Mapping using Cling library in AndroidCreating Overlay (always-on-top) WindowsExoPlayerInter-app UI testing with UIAutomatorMediaSessionSpeech to Text ConversionFileProviderPublish .aar file to Apache Archiva with GradleXMPP register login and chat simple exampleAndroid AuthenticatorRecyclerView and LayoutManagersAudioManagerJob SchedulingAccounts and AccountManagerIntegrate OpenCV into Android StudioSplit Screen / Multi-Screen ActivitiesThreadMediaStoreTime UtilsTouch EventsFingerprint API in androidMVVM (Architecture)BottomNavigationViewORMLite in androidYoutube-APITabLayoutRetrofit2 with RxJavaDayNight Theme (AppCompat v23.2 / API 14+)ShortcutManagerLruCacheJenkins CI setup for Android ProjectsZip file in androidVector DrawablesfastlaneDefine step value (increment) for custom RangeSeekBarGetting started with OpenGL ES 2.0+Check Data ConnectionAndroid Java Native Interface (JNI)FileIO with AndroidPerformance OptimizationRobolectricMoshiStrict Mode Policy : A tool to catch the bug in the Compile Time.Internationalization and localization (I18N and L10N)Fast way to setup Retrolambda on an android project.How to use SparseArrayFirebase Cloud MessagingShared Element TransitionsAndroid ThingsVideoViewViewFlipperLibrary Dagger 2: Dependency Injection in ApplicationsFormatting phone numbers with pattern.How to store passwords securelyAndroid Kernel OptimizationPaintAudioTrackWhat is ProGuard? What is use in Android?Create Android Custom ROMsJava on AndroidPagination in RecyclerViewGenymotion for androidHandling touch and motion eventsCreating Splash screenConstraintSetCleverTapPublish a library to Maven Repositoriesadb shellPing ICMPAIDLAndroid programming with KotlinAutosizing TextViewsSign your Android App for ReleaseContextActivity RecognitionSecure SharedPreferencesSecure SharedPreferencesBitmap CacheAndroid-x86 in VirtualBoxJCodecDesign PatternsOkioGoogle signin integration on androidTensorFlowAndroid game developmentNotification Channel Android OBluetooth Low EnergyLeakcanaryAdding a FuseView to an Android ProjectAccessing SQLite databases using the ContentValues classEnhancing Alert DialogsHardware Button Events/Intents (PTT, LWP, etc.)SpannableStringLooperOptimized VideoViewGoogle Drive APIAnimated AlertDialog BoxAnnotation ProcessorSyncAdapter with periodically do sync of dataCreate Singleton Class for Toast MessageFastjsonAndroid Architecture ComponentsJacksonGoogle Play StoreLoading Bitmaps EffectivelyGetting system font names and using the fontsSmartcardConvert vietnamese string to english string Android

adb shell

Other topics

Send text, key pressed and touch events to Android Device via ADB

execute the following command to insert the text into a view with a focus (if it supports text input)

6.0

Send text on SDK 23+

adb shell "input keyboard text 'Paste text on Android Device'"

If already connected to your device via adb:

input text 'Paste text on Android Device'
6.0

Send text prior to SDK 23

adb shell "input keyboard text 'Paste%stext%son%sAndroid%sDevice'"

Spaces are not accepted as the input, replace them with %s.

Send events

To simulate pressing the hardware power key

adb shell input keyevent 26

or alternatively

adb shell input keyevent POWER

Even if you don't have a hardware key you still can use a keyevent to perform the equivalent action

adb shell input keyevent CAMERA

Send touch event as input

adb shell input tap Xpoint Ypoint

Send swipe event as input

adb shell input swipe Xpoint1 Ypoint1 Xpoint2 Ypoint2 [DURATION*]

*DURATION is optional, default=300ms. source

Get X and Y points by enabling pointer location in developer option.

ADB sample shell script

To run a script in Ubuntu, Create script.sh right click the file and add read/write permission and tick allow executing file as program.

Open terminal emulator and run the command ./script.sh

Script.sh

 for (( c=1; c<=5; c++ ))
    do  
       adb shell input tap X Y
       echo "Clicked $c times"
       sleep 5s
    done

For a comprehensive list of event numbers

List packages

Prints all packages, optionally only those whose package name contains the text in <FILTER>.

adb shell pm list packages [options] <FILTER>

All <FILTER>

adb shell pm list packages

Attributes:

-f to see their associated file.

-i See the installer for the packages.

-u to also include uninstalled packages.

-u Also include uninstalled packages.

Attributes that filter:

-d for disabled packages.

-e for enabled packages.

-s for system packages.

-3 for third party packages.

--user <USER_ID> for a specific user space to query.

Granting & revoking API 23+ permissions

A one-liner that helps granting or revoking vulnerable permissions.

  • granting

    adb shell pm grant <sample.package.id> android.permission.<PERMISSION_NAME>
    
  • revoking

    adb shell pm revoke <sample.package.id> android.permission.<PERMISSION_NAME>
    
  • Granting all run-time permissions at a time on installation (-g)

    adb install -g /path/to/sample_package.apk
    

Print application data

This command print all relevant application data:

  • version code
  • version name
  • granted permissions (Android API 23+)
  • etc..
adb shell dumpsys package <your.package.id>

Recording the display

4.4

Recording the display of devices running Android 4.4 (API level 19) and higher:

adb shell screenrecord [options] <filename>
adb shell screenrecord /sdcard/demo.mp4

(press Ctrl-C to stop recording)

Download the file from the device:

adb pull /sdcard/demo.mp4

Note: Stop the screen recording by pressing Ctrl-C, otherwise the recording stops automatically at three minutes or the time limit set by --time-limit.

adb shell screenrecord --size <WIDTHxHEIGHT>

Sets the video size: 1280x720. The default value is the device's native display resolution (if supported), 1280x720 if not. For best results, use a size supported by your device's Advanced Video Coding (AVC) encoder.


adb shell screenrecord --bit-rate <RATE>

Sets the video bit rate for the video, in megabits per second. The default value is 4Mbps. You can increase the bit rate to improve video quality, but doing so results in larger movie files. The following example sets the recording bit rate to 5Mbps:

adb shell screenrecord --bit-rate 5000000 /sdcard/demo.mp4

adb shell screenrecord --time-limit <TIME>

Sets the maximum recording time, in seconds. The default and maximum value is 180 (3 minutes).


adb shell screenrecord --rotate

Rotates the output 90 degrees. This feature is experimental.


adb shell screenrecord --verbose

Displays log information on the command-line screen. If you do not set this option, the utility does not display any information while running.

Note: This might not work on some devices.

4.4

The screen recording command isn't compatible with android versions pre 4.4

The screenrecord command is a shell utility for recording the display of devices running Android 4.4 (API level 19) and higher. The utility records screen activity to an MPEG-4 file.

Changing file permissions using chmod command

Notice, that in order to change file prmissions, your device need to be rooted, su binary doesn't come with factory shipped devices!

Convention:

adb shell su -c "chmod <numeric-permisson> <file>"

Numeric permission constructed from user, group and world sections.

For example, if you want to change file to be readable, writable and executable by everyone, this will be your command:

adb shell su -c "chmod 777 <file-path>"

Or

adb shell su -c "chmod 000 <file-path>"

if you intent to deny any permissions to it.

1st digit-specifies user permission, 2nd digit- specifies group permission, 3rd digit - specifies world (others) permission.

Access permissions:

--- :   binary value:   000,  octal value: 0 (none)
--x :   binary value:   001,  octal value: 1 (execute)
-w- :   binary value:   010,  octal value: 2 (write)
-wx :   binary value:   011,  octal value: 3 (write, execute)
r-- :   binary value:   100,  octal value: 4 (read)
r-x :   binary value:   101,  octal value: 5 (read, execute)
rw- :   binary value:   110,  octal value: 6 (read, write)
rwx :   binary value:   111,  octal value: 7 (read, write, execute)

Set Date/Time via adb

6.0

Default SET format is MMDDhhmm[[CC]YY][.ss], that's (2 digits each)

For example, to set July 17'th 10:10am, without changing the current year, type:

adb shell 'date 07171010.00'

Tip 1: the date change will not be reflected immediately, and a noticable change will happen only after the system clock advances to the next minute.
You can force an update by attaching a TIME_SET intent broadcast to your call, like that:

adb shell 'date 07171010.00 ; am broadcast -a android.intent.action.TIME_SET'

Tip 2: to synchronize Android's clock with your local machine:

Linux:

adb shell date `date +%m%d%H%M%G.%S`

Windows (PowerShell):

$currentDate = Get-Date -Format "MMddHHmmyyyy.ss" # Android's preferred format
adb shell "date $currentDate"

Both tips together:

adb shell 'date `date +%m%d%H%M%G.%S` ; am broadcast -a android.intent.action.TIME_SET'
6.0

Default SET format is 'YYYYMMDD.HHmmss'

adb shell 'date -s 20160117.095930'

Tip: to synchronize Android's clock with your local (linux based) machine:

adb shell date -s `date +%G%m%d.%H%M%S`

Open Developer Options

adb shell am start -n com.android.settings/.DevelopmentSettings

Will navigate your device/emulator to the Developer Options section.

Generating a "Boot Complete" broadcast

This is relevant for apps that implement a BootListener. Test your app by killing your app and then test with:

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED -c android.intent.category.HOME -n your.app/your.app.BootListener

(replace your.package/your.app.BootListener with proper values).

View external/secondary storage content

View content:

adb shell ls \$EXTERNAL_STORAGE
adb shell ls \$SECONDARY_STORAGE

View path:

adb shell echo \$EXTERNAL_STORAGE
adb shell echo \$SECONDARY_STORAGE

kill a process inside an Android device

Sometimes Android's logcat is running infinitely with errors coming from some process not own by you, draining battery or just making it hard to debug your code.

A convenient way to fix the problem without restarting the device is to locate and kill the process causing the problem.

From Logcat

03-10 11:41:40.010 1550-1627/? E/SomeProcess: ....

notice the process number: 1550

Now we can open a shell and kill the process. Note that we cannot kill root process.

adb shell

inside the shell we can check more about the process using

ps -x | grep 1550

and kill it if we want:

kill -9 1550

Syntax:

  • adb shell [-e escape] [-n] [-Tt] [-x] [command]

Parameters:

ParameterDetails
-echoose escape character, or "none"; default '~'
-ndon't read from stdin
-Tdisable PTY allocation
-tforce PTY allocation
-xdisable remote exit codes and stdout/stderr separation

Contributors

Topic Id: 9408

Example Ids: 3958,3959,3967,3968,9559,14524,16607,18032,18033,18323,29141

This site is not affiliated with any of the contributors.