get Version Name using reflection via android.os.SystemProperties class - Android android.os

Android examples for android.os:SystemProperties

Description

get Version Name using reflection via android.os.SystemProperties class

Demo Code

import java.lang.reflect.Method;

public class Main {

  public static String getVersionName() {
    String miuiVersionName = "";
    try {/*  w  w w .j a va 2s  .c o m*/
      Class<?> SystemProperties = Class.forName("android.os.SystemProperties");
      Method getProperty = SystemProperties.getDeclaredMethod("get", String.class, String.class);

      // Maybe can use ro.miui.ui.version.code ???
      miuiVersionName = (String) getProperty.invoke(SystemProperties, "ro.miui.ui.version.name", "default");
    } catch (Exception e) {
      e.printStackTrace();
    }
    return miuiVersionName;
  }

}

Related Tutorials