Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Road to capture android log using java code

In this post I will show you how to capture android log using java code.
public static void captureAndroidDevicesLog() {
  try {
   Process process = Runtime.getRuntime().exec("adb logcat");

   BufferedReader reader = new BufferedReader(new InputStreamReader(
         process.getInputStream()));
   String s;
   System.out.println("*********************************************");
   System.out.println("Printing android logs");
   System.out.println("*********************************************");
   while ((s = reader.readLine()) != null) {
    System.out.println(s);
   }
   System.out.println("*********************************************");
   System.out.println("End printing android logs");
   System.out.println("*********************************************");
  } catch (IOException e) {
   e.printStackTrace();
  } 
}

Above code capture all log of android device and print in console. Yo can manupulate as per you need.

Road to capture all connected devices using java code at run time

In this post you will learn how to capture connected devices udid at run time using java code.

public static List<String> getAttachedDevicesList(){
 
  List<String> devicesID = new ArrayList<String>();
  try {
         Process process = Runtime.getRuntime().exec("adb devices");       
         BufferedReader reader=new BufferedReader( new InputStreamReader(process.getInputStream()));
         String s;                
         while ((s = reader.readLine()) != null){         
          if(s.contains("device") && ! s.contains("attached")){
           String[] device = s.split("\t");
           devicesID.add(device[0]);
          }
         }  
        
     } catch (IOException e) {
         e.printStackTrace();
     }
     return devicesID;
 }


public static void main(String[] str) {
  List<String> devicesID = getAttachedDevicesList();
  for (String dvc : devicesID) {
   System.out.println(dvc);
  }
 }

When you run this you will get  all connected devices  udid.

Road to create Virtual device (Emulator ) for beginner

In this post I will show you how to install android SDK , setup Android SDK path in system environments variable, How to update android API and how to create Virtual Devices.

Installation:
  1. Download Androd sdk exe or Zip file from link: download
  2. Install exe file in your machine or extract the zip file.
Setup Path:
1. Right click on the "My Computer" icon.
2. Click Properties
3. Click Advanced tab
4. Click Environment Variables button, You should see below screen: