0

How to get android version of my device programmatically when debugging via usb? I saw a link with this line of code but I reckon this gets the build/version number of the app and not that of the OS of the actual device

packageinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
Version = packageinfo.versionName.toString();

in my code this is what I have for application names etc , within here I would like to get android version of the actual device I am using to debug(Samsung GT-I9300)

MY CODE

 ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
      NetworkInfo info = cm.getActiveNetworkInfo();
      int networkType = NetworkState.GetNetworkState(context, info, "DataUsageRecorder"); // wifi, data, data roaming

      // Get all apps
      PackageManager pm = context.getPackageManager();
      for (ApplicationInfo app : pm.getInstalledApplications(0))
      {

         long tx = 0;
         long rx = 0;
         int uid = app.uid;


            tx = TrafficStats.getUidTxBytes(uid);
            rx = TrafficStats.getUidRxBytes(uid);


         if ((tx == 0 || rx == 0))
         {
            // Skip inactive items
            continue;
         }
         else if (Globals.DEBUG && (tx < DEBUG_5MB && rx < DEBUG_5MB))
         {
            // Let's skip all the BS for quick testingFlog
            continue;
         }
Cœur
  • 37,241
  • 25
  • 195
  • 267
Zidane
  • 1,696
  • 3
  • 21
  • 35
  • I really don't know how you searched. But there are a lot of answers available. Check this link http://stackoverflow.com/questions/3423754/retrieving-android-api-version-programmatically – Luke Villanueva May 10 '16 at 17:38

1 Answers1

3

You can use android.os.Build.VERSION.SDK_INT.

Undo
  • 25,519
  • 37
  • 106
  • 129
daxgirl
  • 762
  • 4
  • 10