Guest User

Untitled

a guest
Feb 21st, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. /**
  2. * Get Device Name with Manufacturer
  3. */
  4. public static String getDeviceName() {
  5. String manufacturer = Build.MANUFACTURER;
  6. String model = Build.MODEL;
  7. if (model.startsWith(manufacturer)) {
  8. return capitalize(model);
  9. } else {
  10. return capitalize(manufacturer) + " " + model;
  11. }
  12. }
  13.  
  14. /**
  15. * Get Device OS
  16. */
  17. public static String getDeviceOS() {
  18. String osVersion = Build.VERSION.RELEASE;
  19. return capitalize(osVersion);
  20. }
  21.  
  22. /**
  23. * Get Screen Width & Height
  24. */
  25. public static String getScreenDimensions(Activity activity) {
  26.  
  27. final DisplayMetrics dm = new DisplayMetrics();
  28. final android.view.Display display = activity.getWindowManager().getDefaultDisplay();
  29. display.getMetrics(dm);
  30.  
  31. int screenWidth = dm.widthPixels;
  32. int screenHeight = dm.heightPixels;
  33.  
  34. if (Build.VERSION.SDK_INT >= 15 && Build.VERSION.SDK_INT < 17) {
  35. try {
  36. screenWidth = (Integer) android.view.Display.class.getMethod("getRawWidth").invoke(display);
  37. screenHeight = (Integer) android.view.Display.class.getMethod("getRawHeight").invoke(display);
  38. } catch (Exception ignored) {
  39. }
  40. }
  41. if (Build.VERSION.SDK_INT >= 17) {
  42. try {
  43. Point realSize = new Point();
  44. android.view.Display.class.getMethod("getRealSize", Point.class).invoke(display, realSize);
  45. screenWidth = realSize.x;
  46. screenHeight = realSize.y;
  47. } catch (Exception ignored) {
  48. }
  49. }
  50.  
  51. return "Width- " + screenWidth + " Height- " + screenHeight;
  52. }
  53.  
  54. /**
  55. * Get Device primary Email Add
  56. */
  57. public static String getUserPrimaryEmail(Context context) {
  58. String primaryEmail = "";
  59. AccountManager manager = AccountManager.get(context);
  60. if (ActivityCompat.checkSelfPermission(context, Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) {
  61. Account[] accounts = manager.getAccountsByType("com.google");
  62. List<String> possibleEmails = new LinkedList<String>();
  63.  
  64. for (Account account : accounts) {
  65. // account.name as an email address only for certain account.type values.
  66. possibleEmails.add(account.name);
  67. }
  68.  
  69. if (!possibleEmails.isEmpty() && possibleEmails.get(0) != null) {
  70. primaryEmail = possibleEmails.get(0);
  71. }
  72. }
  73.  
  74. return primaryEmail;
  75. }
  76.  
  77. /**
  78. * Get User Keyboard
  79. */
  80. public static String getUserKeyboard(Context context) {
  81. return Settings.Secure.getString(context.getContentResolver(), Settings.Secure.DEFAULT_INPUT_METHOD);
  82. }
  83.  
  84. /**
  85. * Get Display Density DPI
  86. */
  87. public static String getDensityDpi(Context context) {
  88. try {
  89. DisplayMetrics metrics = context.getResources().getDisplayMetrics();
  90. return (int) (metrics.density * 160f) + " DPI";
  91.  
  92. } catch (Exception e) {
  93. e.printStackTrace();
  94. return "";
  95. }
  96. }
  97.  
  98. /**
  99. * Checks if the device is rooted.
  100. *
  101. * @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
  102. */
  103. public static boolean isRooted() {
  104.  
  105. // get from build info
  106. String buildTags = android.os.Build.TAGS;
  107. if (buildTags != null && buildTags.contains("test-keys")) {
  108. return true;
  109. }
  110.  
  111. // check if /system/app/Superuser.apk is present
  112. try {
  113. File file = new File("/system/app/Superuser.apk");
  114. if (file.exists()) {
  115. return true;
  116. }
  117. } catch (Exception e1) {
  118. // ignore
  119. }
  120.  
  121. // try executing commands
  122. return canExecuteCommand("/system/xbin/which su")
  123. || canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");
  124. }
  125.  
  126. // executes a command on the system
  127. private static boolean canExecuteCommand(String command) {
  128. boolean executedSuccesfully;
  129. try {
  130. Runtime.getRuntime().exec(command);
  131. executedSuccesfully = true;
  132. } catch (Exception e) {
  133. executedSuccesfully = false;
  134. }
  135.  
  136. return executedSuccesfully;
  137. }
Add Comment
Please, Sign In to add comment