Friday, 8 January 2016

Important ADB/Android Commands

ADB Commands

                Shell commands for opening any URLs with any Mobile web browsers

Pre-condition
1.        Install  Chrome, Mozilla, Opera apps or any other browsers from Play store
2.       At first time launch, Do the browser setting and Open any sites at first launch

Shell Commands Step by Step

Step 1:  Make sure devices are detecting with adb devices
Step 2:  Type the below command and re place URL as below mentioned with green color
Note: If URL has any special characters such as “@$&() ..etc”, Pass URL with cotes(“ ”).


Chrome App

adb shell am start -a android.intent.action.VIEW -n com.android.chrome/.Main -d “http://igate.com

Mozilla App

adb shell am start -a android.intent.action.VIEW -n org.mozilla.firefox/.App -d “http://google.com

Opera App

adb shell am start -a android.intent.action.VIEW -n com.opera.mini.android/.Browser -d http://google.com
You can also apply the same command for other mobile browsers as well.
Only you need to get the target package name of the browser and startup activity name of the browser applciation.

For example:
adb shell am start -a android.intent.action.VIEW -n XXX.XXX.XXX /.XXX -d XXXURLXXX



Device Orientation

disable accelerometer controlling rotation - just do this once
adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0
rotate landscape:
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:1
rotate portrait:
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0
rotate upside down landscape:
adb shell content insert --uri content://settings/system  --bind name:s:user_rotation --bind value:i:3
rotate upside down portrait:
adb shell content insert --uri content://settings/system  --bind name:s:user_rotation --bind value:i:2
If you have WRITE_SETTINGS permission you can write thru the content provider in java code as well.
  
Other ADB Commands

To get all the Properties of the Device:
                adb shell getprop
To get particular property:
            adb shell getprop ro.product.model
Key events:
                adb shell input keyevent 82   (Menu Info)
                adb shell input keyevent 3  (Home)

Screen Record
adb shell screenrecord Filename.mp4


Signing Android Application with own Signature/Signing Your App Manually

Signing Android Application with own Signature/Signing Your App Manually:

It's not required to have Android SDK to resign your application. You can sign your application (.apk file) with your own signature from command line tools using standard tools and JDK. Just follow below steps to sign your app using Command Prompt
  1. Generate a private key using Keytool. Ex:
Use the below command to generate Keystore:
Command:     keytool -genkey --keystore default.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
This prompts you for passwords for the keystore and key, and to provide the Distinguished Name fields for your key. It then generates the keystore as a file called my-release-key.keystore. The keystore contains a single key, valid for 10000 days. The alias is a name that you will use later when signing your app
  1. Compile your app in release mode to obtain an unsigned APK
  2. Sign your app with your private key using jarsigner:
Command:   jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore
Type this command in Java installed path i.e.., Ex: C:\Program Files\Java\jdk1.7.0_51\bin\ - - Command - -
This example prompts you for passwords for the keystore and key. It then modifies the APK in-place to sign it. Note that you can sign an APK multiple times with different keys
  1. Verify that your APK is signed. For example:
Command:  jarsigner -verbose –keystore “dubug.keystore” zippedAPp.apk androiddebugkey
  1. Align the final APK package using zipalign
Command:  zipalign -v 4 your_project_name-unaligned.apk your_project_name.apk
ZIPALIGN ensures that all uncompressed data starts with a particular byte alignment relative to the start of the file, which reduces the amount of RAM consumed by an app

For more details Refer to following link: http://developer.android.com/tools/publishing/app-signing.html