Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Get Device Name with Manufacturer
- */
- public static String getDeviceName() {
- String manufacturer = Build.MANUFACTURER;
- String model = Build.MODEL;
- if (model.startsWith(manufacturer)) {
- return capitalize(model);
- } else {
- return capitalize(manufacturer) + " " + model;
- }
- }
- /**
- * Get Device OS
- */
- public static String getDeviceOS() {
- String osVersion = Build.VERSION.RELEASE;
- return capitalize(osVersion);
- }
- /**
- * Get Screen Width & Height
- */
- public static String getScreenDimensions(Activity activity) {
- final DisplayMetrics dm = new DisplayMetrics();
- final android.view.Display display = activity.getWindowManager().getDefaultDisplay();
- display.getMetrics(dm);
- int screenWidth = dm.widthPixels;
- int screenHeight = dm.heightPixels;
- if (Build.VERSION.SDK_INT >= 15 && Build.VERSION.SDK_INT < 17) {
- try {
- screenWidth = (Integer) android.view.Display.class.getMethod("getRawWidth").invoke(display);
- screenHeight = (Integer) android.view.Display.class.getMethod("getRawHeight").invoke(display);
- } catch (Exception ignored) {
- }
- }
- if (Build.VERSION.SDK_INT >= 17) {
- try {
- Point realSize = new Point();
- android.view.Display.class.getMethod("getRealSize", Point.class).invoke(display, realSize);
- screenWidth = realSize.x;
- screenHeight = realSize.y;
- } catch (Exception ignored) {
- }
- }
- return "Width- " + screenWidth + " Height- " + screenHeight;
- }
- /**
- * Get Device primary Email Add
- */
- public static String getUserPrimaryEmail(Context context) {
- String primaryEmail = "";
- AccountManager manager = AccountManager.get(context);
- if (ActivityCompat.checkSelfPermission(context, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) {
- Account[] accounts = manager.getAccountsByType("com.google");
- List<String> possibleEmails = new LinkedList<String>();
- for (Account account : accounts) {
- // account.name as an email address only for certain account.type values.
- possibleEmails.add(account.name);
- }
- if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) {
- primaryEmail = possibleEmails.get(0);
- }
- }
- return primaryEmail;
- }
- /**
- * Get User Keyboard
- */
- public static String getUserKeyboard(Context context) {
- return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
- }
- /**
- * Get Display Density DPI
- */
- public static String getDensityDpi(Context context) {
- try {
- DisplayMetrics metrics = context.getResources().getDisplayMetrics();
- return (int) (metrics.density * 160f) + " DPI";
- } catch (Exception e) {
- e.printStackTrace();
- return "";
- }
- }
- /**
- * Checks if the device is rooted.
- *
- * @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
- */
- public static boolean isRooted() {
- // get from build info
- String buildTags = android.os.Build.TAGS;
- if (buildTags != null && buildTags.contains("test-keys")) {
- return true;
- }
- // check if /system/app/Superuser.apk is present
- try {
- File file = new File("/system/app/Superuser.apk");
- if (file.exists()) {
- return true;
- }
- } catch (Exception e1) {
- // ignore
- }
- // try executing commands
- return canExecuteCommand("/system/xbin/which su")
- || canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
- }
- // executes a command on the system
- private static boolean canExecuteCommand(String command) {
- boolean executedSuccesfully;
- try {
- Runtime.getRuntime().exec(command);
- executedSuccesfully = true;
- } catch (Exception e) {
- executedSuccesfully = false;
- }
- return executedSuccesfully;
- }
Add Comment
Please, Sign In to add comment