return -1; } } return 0; } else { return diff > 0 ? 1 : -1; }
}
### [] (II) installation of apk
/**
-
Install APK
-
@param context
-
@param filePath
*/
public static void installApk(Context context, String filePath) {
try { /** * provider * Handle the abnormal installation of android 7.0 and above systems */ File file = new File(filePath); Intent install = new Intent(); install.setAction(Intent.ACTION_VIEW); install.addCategory(Intent.CATEGORY_DEFAULT); install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Uri apkUri = FileProvider.getUriForFile(context, "Package name.fileprovider", file);//android:authorities value in Android manifest install.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);//Adding this sentence means temporarily authorizing the file represented by the Uri for the target application install.setDataAndType(apkUri, "application/vnd.android.package-archive"); } else { install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); } context.startActivity(install); } catch (Exception e) { //TODO file parsing failed }
}
### [] (III) obtain the unique identification of the equipment ##### [] () Note: we didn't get IMEI here, because if we need to dynamically apply for permission to get equipment status to get IMEI value, the cost is relatively high for users. In addition, when using a custom device, it was found that the device has no IMEI value, and an error will be reported all the time.
/**
-
Get the unique identification of the device and send the ANDROID_ID and serial number are spliced and converted into MD5 format for return
-
@param context context
-
@return unique ID of the device
*/
public static String getUniqueId(Context context) {
String androidID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); String id = androidID + Build.SERIAL; try { return toMD5(id); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return id; }
}
/**
-
Convert string to MD5
-
@Param textstring to convert
-
@return converted string
-
@throws NoSuchAlgorithmException
*/
private static String toMD5(String text) throws NoSuchAlgorithmException {
//Get digester MessageDigest MessageDigest messageDigest = MessageDigest.getInstance("MD5"); //hash the binary byte array of the string through the digester byte[] digest = messageDigest.digest(text.getBytes()); StringBuilder sb = new StringBuilder(); for (int i = 0; i < digest.length; i++) { //Loop each character to convert the calculation result into a positive integer; int digestInt = digest[i] & 0xff; //Convert decimal to shorter hexadecimal String hexString = Integer.toHexString(digestInt); //If the conversion result is a single digit, 0 will be omitted, so judge and supplement 0 if (hexString.length() < 2) { sb.append(0); } //Adds the loop result to the buffer sb.append(hexString); } //Returns the entire result return sb.toString();
}
### [] (IV) obtain the mac address of the device
/**
-
Get device MAC address
-
Permissions to be added: INTERNET, ACCESS_WIFI_STATE
-
@return the Mac address of the device
*/
Epilogue
Some students in the comments have questions about how to learn material design controls. My suggestion is to search GitHub. There are many examples given by peers. These chestnuts are enough to get started.
A friend said that if you are serious, you need knowledge of NDK and JVM. For the first time * * NDK is not a mysterious thing, * * you can know what's going on by following the official steps. It's nothing more than some code formats and native / JAVA memory interaction. More advanced is native / java thread interaction. Thread interaction is really a little painful, but it's better to avoid it, Besides, what do you care about NDK for beginners? According to my previous experience, I have only used it in audio and video communication and an embedded signal processing (offline). Embedded signal processing is called by Java - > NDK - > SO - > MATLAB. Most of my original MATLAB codes are used in games, General Internet companies will have someone give your SO package.
As for the part of JVM that should be mastered, believe me, you will master, but you shouldn't. those who specialize in JVM will do it. It's better to save your worry and have a look at the computer system and compilation principle when you have time.
In a word, writing more and practicing more is the most basic quality of programmers. Try to squeeze time and read basic theoretical books. JVM is not the only virtual machine in the next 30 years, and JAVA may not be popular in the industry in the next 30 years. Other systems and languages will spring up, but your solid theory will enable you to quickly understand and learn a language or framework, If you write more often, you will quickly and skillfully apply the new things to practice.
Beginners, one word, practice more.