Friday, 12 August 2016

Android ADB Commands, Tricks & Hacks

Android ADB Commands & Tricks

Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android device. It facilitates a variety of device actions, such as installing and debugging apps, and it provides access a Unix shell that you can use to run a variety of commands on an emulator or connected device. It is a client-server program that includes three components:
  • A client, which sends commands. The client runs on your development machine. You can invoke a client from a command-line terminal by issuing an adb command.
  • A daemon, which runs commands on a device. The daemon runs as a background process on each emulator or device instance.
  • A server, which manages communication between the client and the daemon. The server runs as a background process on your development machine.
read more

adb devices 

list all the devices which is connected with the system.

adb -e shell

open emulator shell

adb -d shell

open device shell

what if we have more than 2 emulators or devices

adb -s <serial no> shell

use serial number to open device shell

adb  shell pm list packages 

list all the installed app package name.

but how to get debugable apps package name

adb jdwp
list all debugable apps process id

adb shell cat /proc/<process id>/cmdline 
              or  
adb shell cat /proc/<process id>/comm  

use process id to get the package name

adb shell ps <process id>

use process id to know the process information

you can fire all those cmd in adb shell also

$adb shell

to enter in android shell

$cat /proc/<process id>/cmdline 
               or  
$cat /proc/<process id>/comm
use process id to get the package name

$ps <process id>

use process id to know the process information

some more interesting commands

Dial Number: 

adb shell service call phone 1 s16 "+9191919191" 

here phone is a service, 1 is service code & s16 is parameter type and "+9191919191" is a parameter value.

Call Number:

adb shell service call phone 2 s16 "" s16 "+9191919191"

here phone is a service, 2 is service code & s16 is a 1st parameter type but no value & s16 is a 2nd parameter type and "+9191919191" is a parameter value.

Kill-APP:

adb  shell am force-stop <package name> 

Start App

adb shell monkey -p <package name> -c android.intent.category.LAUNCHER 1

Pull Down StatusBar

adb shell service call statusbar 1

Pull Up StatusBar

adb shell service call statusbar 2

wakeup/Sleep device

adb shell input keyevent 26 

unlock device

adb shell input keyevent 82

others services

adb shell service list

 

 




 

Wednesday, 20 May 2015

How to create CircleDrawable in Android

 public class CircleDrawable extends Drawable { 
   float width; 
   float height; 
   Paint mPaint; 
   RectF mRectf; 
   Paint mPaintR; 
   public CircleDrawable(float width, float height, int color) { 
     this.width = width; 
     this.height = height; 
     mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); 
     mPaint.setColor(color); 
     mPaint.setStyle(Paint.Style.FILL); 
     mPaintR = new Paint(Paint.ANTI_ALIAS_FLAG); 
     mPaintR.setColor(Color.RED); 
     mPaintR.setStyle(Paint.Style.STROKE); 
     mPaintR.setStrokeWidth(10f); 
     mRectf = new RectF(0, 0, width, height); 
     // mRectf.offset((getMinimumWidth() - width) / 2, (getMinimumHeight() - height) / 2); 
   } 
   @Override 
   public void draw(Canvas canvas) { 
     // canvas.drawRect(mRectf, mPaintR); 
     canvas.drawCircle(mRectf.centerX(), mRectf.centerY(), width / 2, mPaint); 
   } 
   @Override 
   public void setAlpha(int alpha) { 
   } 
   @Override 
   public void setColorFilter(ColorFilter cf) { 
   } 
   @Override 
   public int getOpacity() { 
     return 0; 
   } 
 } 

Thursday, 25 December 2014

How to Proguard Android APK

How to Proguard Android APK


-in jars: Specifies the input jars (or aars, wars, ears, zips, apks, or directories) of the application to be processed

-outjars:Specifies the names of the output jars (or aars, wars, ears, zips, apks, or directories). The processed input of the preceding -injars options will be written to the named jars.

-libraryjars: Specifies the library jars (or aars, wars, ears, zips, apks, or directories) of the application to be processed. The files in these jars will not be included in the output jars.

-dontskipnonpubliclibraryclassmembers: Specifies not to ignore package visible library class members (fields and methods).

-keep: Specifies classes and class members (fields and methods) to be preserved as entry points to your code.

Here  ReportingInteractionMode is a class in ACRA library. we have to keep this library in src to suppress Crash No such filed TOAST.
-keep class org.acra.ReportingInteractionMode { *; }  

Copy this contain and create file proguard.cfg and past into it.

 -injars   bin/classes  
 -injars   libs  
 -outjars   bin/classes-processed.jar  
 -libraryjars /home/.../adt-bundle-linux-x86-20140321/sdk/platforms/android-19/android.jar  
 -libraryjars /home/.../libs/android-query-full.0.26.7.jar  
 -libraryjars /home/.../libs/javassist.jar  
 -libraryjars /home/.../libs/joda-time-2.3.jar  
 -libraryjars /home/.../libs/libphonenumber-5.9.jar  
 -libraryjars /home/.../libs/nineoldandroids-2.4.0.jar  
 -optimizationpasses 1  
 -dontpreverify  
 -dontskipnonpubliclibraryclassmembers  
 -repackageclasses ''  
 -allowaccessmodification  
 -optimizations !code/simplification/arithmetic,!field  
 -keepattributes *Annotation*       
 -dontusemixedcaseclassnames  
 -dontskipnonpubliclibraryclasses  
 -dontpreverify  
 -verbose  
 -allowaccessmodification  
 -keepattributes *Annotation*  
 -dontwarn android.support.v7.**  
 -dontwarn in.android.Databases.**  
 -dontwarn in.android.PushNotification.**  
 -dontwarn in.andoroid.Utills.FileUtill  
 -dontwarn android.support.v4.**  
 -dontwarn com.androidquery.auth.**  
 -dontwarn javassist.**  
 -dontwarn org.brickred.socialauth.**  
 -dontwarn org.joda.time.**  
 -keep public class * extends android.app.Activity  
 -keep public class * extends android.app.Application  
 -keep public class * extends android.app.Service  
 -keep public class * extends android.content.BroadcastReceiver  
 -keep public class * extends android.content.ContentProvider  
 -keep public class com.android.vending.licensing.ILicensingService  
 -keepclasseswithmembernames class * {  
   native <methods>;  
 }  
 -keepclasseswithmembernames class * {  
   public <init>(android.content.Context, android.util.AttributeSet);  
 }  
 -keepclasseswithmembernames class * {  
   public <init>(android.content.Context, android.util.AttributeSet, int);  
 }  
 -keepclassmembers enum * {  
   public static **[] values();  
   public static ** valueOf(java.lang.String);  
 }  
 -keep class * implements android.os.Parcelable {  
  public static final android.os.Parcelable$Creator *;  
 }  
 # for minmize ACRA library Error we are using this ReportingInteractionMode   
 # otherwise you will get No Such field Toast   
 -keep class org.acra.ReportingInteractionMode { *; }  

In project.properties add this attribute and save it.

proguard.config=proguard.cfg 

then, export the project and create new keystore if you haven't created or use existing keystore and finish the wizard.

Monday, 22 December 2014

How to use Curl Library in Android


To compile Curl library for android, follow this post

Here is the simple Android Example using Curl Library.
Source Code:https://github.com/JohnnyIqbal/AndroidCurlEx

How to compile Curl Library for Android in Linux


1. Download the source code of curl library http://curl.haxx.se/download.html

2.Create a file build_andorid.sh and copy below content and save file into Curl folder.

 #!/bin/bash  
 NDK=<yourpath>/android-ndk-r9d  
 SYSROOT=$NDK/platforms/android-19/arch-arm/  
 CFLAGS="-fno-exceptions -Wno-multichar -mthumb -mthumb-interwork -nostdlib -lc -ldl -lm "  
 LDFLAGS="-Wl,--fix-cortex-a8"   
 export AR="$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-ar"  
 export LD="$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-ld"  
 export CC="$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc --sysroot=$SYSROOT"  
 ./configure \  
 --host=arm-linux-androideabi \  
 --prefix=/<your output folder path where include,lib and bin will folder copy >/curllib/ \  
 --exec-prefix=/<your output folder path where include,lib and bin will folder copy >/curllib/  
 make clean  
 make  
 make install  

3.Change build_android.sh mode to executable mode,Open terminal and head(i,e. cd)  to curl directory and run below code.

 sudo chmod +x 777 build_android.sh  
 ./build_android.sh  

4. If you want to download compiled curl library  for android click below link
https://github.com/JohnnyIqbal/Curl_For_Android_Compiled

5. Android Example of Curl Library https://github.com/JohnnyIqbal/AndroidCurlEx

Tuesday, 16 December 2014

How to port C library to Android as a static library.

Hi,

How to port C library to Android as a static library.

We build the  C library as a static library(*.a) and build a shared library using static library. because Android packaged only shared library in apk.
SourceCode Link:https://github.com/JohnnyIqbal/PortStaticEx.git

How to port C library to Android as a shared library(.so)

Hi,

How to port C library to Android as a shared library(.so).

We build C library as a shared library for android because android packaged only shared library in apk.

SourceCode Link:https://github.com/JohnnyIqbal/PortSharedEx.git

Things after Kotlin Android Extensions

Things after Kotlin Android Extensions(KTX) I remembered in MVVM when I have to declare ViewModel, I initialize View Model like this. p...