Mainly introduced in the summary of Android development commonly used tool classes, most of the same applies to Java.
Currently includes Httputils, Downloadmanagerpro, Safe.ijiami, Shellutils, Packageutils, Preferencesutils, JSONUtils, FileUtils, Resourceutils, StringUtils, Parcelutils, Randomutils, Arrayutils, Imageutils, Listutils, MapUtils, ObjectUtils, Serializeutils, Systemutils, Timeutils.
1, Httputils
HTTP Network tool classes, mainly including HttpGet, HttpPost, and HTTP parameter related methods, take httpget as an example:
Static HttpResponse HttpGet (HttpRequest request)
Static HttpResponse HttpGet (java.lang.String httpurl)
static string httpgetstring (String httpurl)
Contains the above three methods, using GZIP compression by default, using BufferedReader to improve read speed.
HttpRequest can set the URL, timeout, useragent and other HTTP parameters
Return content, HTTP response code, HTTP Expiration Time (Cache-control Max-age and expires) can be obtained in HttpResponse, etc.
The first two methods can be advanced parameter setting and rich content return, the third method can simply pass in the URL to get the return content, httppost similar. More detailed settings can be used directly with the HttpURLConnection or Apache httpclient.
Source visible Httputils.java, more methods and more detailed parameters of the Httputils Api Guide can be seen.
2, Downloadmanagerpro
Android system Download Management Downloadmanager enhancement method that can be used to include information about downloads such as:
Getstatusbyid (long) Get download status
Getdownloadbytes (long) get Download progress information
Getbytesandstatus (long) Get download progress information and status
GetFileName (long) get the download file path
GetURI (long) get download URI
GetReason (long) gets the download failure or pause reason
Getpausedreason (long) get download pause reason
GetErrorCode (long) get download error code
Source visible Downloadmanagerpro.java, more methods and more detailed parameters of the Downloadmanagerpro Api Guide can be seen.
3, Safe.ijiami
Android Vulnerability Detection Tool, online upload Android apk, detect the APK development process generated by some vulnerable hackers exploit, attack vulnerability, based on the vulnerability of the corresponding solution, a key to generate detailed analysis report, Let Android developers know the vulnerabilities of their Android apps at a glance and take steps to protect them in a timely manner.
4, Shellutils
The Android Shell tool class, which can be used to check system root permissions and execute shell commands under the shell or root user. such as: Checkrootpermission () check root permissions execcommand (string[] commands, Boolean isRoot, Boolean isneedresultmsg) Shell Environment Execution command, The second parameter indicates whether the root permission executes execcommand (String command, Boolean isRoot) Shell Environment Execution command
Source visible Shellutils.java, more methods and more detailed parameters of the Shellutils Api Guide can be seen.
5, Packageutils
Android Package Related tool class, can be used to (root) install the application, (root) Uninstall the application, determine whether the system application, etc.
such as: Install (context, string) installation of the application, if it is a system application or has root, then silent installation, otherwise generally installed uninstall (context, string) uninstall the application, if the system is applied or has root, then silently uninstall, Otherwise general unload issystemapplication (Context, String) to determine whether the application is applied to the system
Source visible Packageutils.java, more methods and more detailed parameters of the Shellutils Api Guide can be seen.
6, Preferencesutils
Android Sharedpreferences Related Tool class, which can be used to easily read and write related type data to sharedpreferences, such as: Putstring (Context, String, String) Save the String class Type of data
Putint (Context, String, int) holds int type data
GetString (Context, String) Gets the String type data
GetInt (Context, String) gets the int type data
You can modify the preference name by modifying the preference_name variable
Source visible Preferencesutils.java, more methods and more detailed parameters of the Preferencesutils Api Guide can be seen.
7, Jsonutils
The Jsonutils tool class can be used to easily read and write related types of data to JSON, such as:
String getString (Jsonobject jsonobject, string key, String defaultvalue) Gets the string type value
String getString (String jsondata, String key, String defaultvalue) Gets the string type value
Represents the value of reading a string type key from JSON
Getmap (Jsonobject jsonobject, String key) get map
Getmap (String jsondata, string key) get map
Represents the value of reading a map type key from JSON
Source visible Jsonutils.java, more methods and more detailed parameters of the Jsonutils Api Guide can be seen.
8, FileUtils
A file tool class that can be used to read and write files and manipulate files. Such as:
ReadFile (String filePath) Read file
WriteFile (string FilePath, String content, Boolean append) write file
GetFileSize (String Path) to get the file size
DeleteFile (String path) Delete file
Source visible Fileutils.java, more methods and more detailed parameters of the Fileutils Api Guide can be seen.
9, Resourceutils
The Android Resource tool class can be used to read content from the raw and assets directories of the Android resource directory, such as:
Gefilefromassets (context context, String fileName) Gets the contents of a file in the assets directory
Gefilefromraw (context context, int resId) Gets the contents of a file in the raw directory
Source visible Resourceutils.java, more methods and more detailed parameters of the Resourceutils Api Guide can be seen.
10, StringUtils
The String tool class, which can be used for common string operations, such as:
IsEmpty (String str) determines whether a string is empty or has a length of 0
IsBlank (String str) determines whether a string is empty or has a length of 0 or consists of spaces
Utf8encode (String str) encoded in UTF-8 format
Capitalizefirstletter (String str) Capitalize first letter
Source visible Stringutils.java, more methods and more detailed parameters of the StringUtils Api Guide can be seen.
11, Parcelutils
The Android Parcel tool class, which can be used to read or write special types of data from parcel such as:
Readboolean (Parcel in) Read Boolean type data from Pacel
Readhashmap (Parcel in, ClassLoader loader) read map type data from Pacel
Writeboolean (Boolean B, Parcel out) writes Boolean type data to Parcel
Writehashmap (map<k, v> map, Parcel out, int flags) write MAP type data to Parcel
Source visible Parcelutils.java, more methods and more detailed parameters of the Parcelutils Api Guide can be seen.
12, Randomutils
The random Number tool class, which can be used to obtain a random number of fixed-size fixed character characters, such as:
Getrandom (char[] sourcechar, int length) generates a random string, all characters nonspacing within a string
getrandomnumbers (int length) generates random numbers
Source visible Randomutils.java, more methods and more detailed parameters of the Randomutils Api Guide can be seen.
13, Arrayutils
Array tool class, which can be used for array common operations, such as:
IsEmpty (v[] sourcearray) to determine whether the array is empty or the length is 0
GetLast (v[] sourcearray, v value, v DefaultValue, Boolean iscircle) gets the previous element of an element in the array, iscircle indicates whether to loop
GetNext (v[] sourcearray, v value, v DefaultValue, Boolean iscircle) gets the next element of an element in the array, iscircle indicates whether to loop
Source visible Arrayutils.java, more methods and more detailed parameters of the Arrayutils Api Guide can be seen.
14, Imageutils
The Picture tool class, which can be used for conversion between bitmap, byte array, drawable, and image scaling, is currently weak and will be enhanced later. Such as:
Bitmaptodrawable (Bitmap B) bimap convert to Drawable
Drawabletobitmap (drawable D) drawable convert to bitmap
Drawabletobyte (drawable D) drawable convert to Byte
Scaleimage (Bitmap org, float scalewidth, float scaleheight) zoom picture
Source visible Imageutils.java, more methods and more detailed parameters of the Imageutils Api Guide can be seen.
15, Listutils
The list tool class, which can be used for list common operations, such as:
IsEmpty (list<v> sourceList) determines whether the List is empty or has a length of 0
Join (list<string> list, string separator) list is converted to a string and split with a fixed delimiter
Adddistinctentry (list<v> sourceList, V Entry) adding non-repeating elements to the list
Source visible Listutils.java, more methods and more detailed parameters of the Listutils Api Guide can be seen.
16, Maputils
The Map tool class, which can be used for map common operations such as:
IsEmpty (map<k, v> sourcemap) determine if the Map is empty or length is 0
Parsekeyandvaluetomap (string source, String keyandvalueseparator, String Keyandvaluepairseparator, Boolean Ignorespace) string parsing to map
ToJson (map<string, string> map) map converted to JSON format
Source visible Maputils.java, more methods and more detailed parameters of the Maputils Api Guide can be seen.
17, Objectutils
The Object tool class, which can be used for object common operations, such as:
Isequals (object actual, object expected) compares two objects for equality
Compare (v v1, v V2) compare two object sizes
Transformintarray (int[] source) Integer array converted to int array
Source visible Objectutils.java, more methods and more detailed parameters of the Objectutils Api Guide can be seen.
18, Serializeutils
A serialization tool class that can be used to serialize an object to a file or deserialize an object from a file, such as:
Deserialization (String FilePath) Deserializes an object from a file
Serialization (String FilePath, Object obj) serializes objects to a file
Source visible Serializeutils.java, more methods and more detailed parameters of the Serializeutils Api Guide can be seen.
19, Systemutils
The System Information tool class, which can be used to get the appropriate size of the thread pool, is currently weak and will be enhanced later. Such as:
Getdefaultthreadpoolsize () Get the thread pool size that matches the system configuration
Source visible Systemutils.java, more methods and more detailed parameters of the Systemutils Api Guide can be seen.
20, Timeutils
Time tool class that can be used for time-related operations such as:
Getcurrenttimeinlong () Gets the current time
GetTime (Long Timeinmillis, SimpleDateFormat DateFormat) converts a long to a fixed-format time string
Source visible Timeutils.java, more methods and more detailed parameters of the Timeutils Api Guide can be seen.
20 Common tools for Android development