Android Development Common Tool class

Source: Internet
Author: User
Tags response code

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 for example:         static HttpResponse HttpGet (HttpRequest request)         static HttpResponse HttpGet ( Java.lang.String httpurl)         static string httpgetstring (String httpurl)         includes the three methods above, using gzip compression by default, and using BufferedReader to improve read speed.         HttpRequest can set other HTTP parameters such as URL, timeout, useragent, etc.          HttpResponse can get back content, HTTP response code, HTTP Expiration Time (Cache-control Max-age and expires)          the top 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, which can be used to include information about obtaining downloads, such as: Getstatusbyid (long) Get download status getdownloadbytes (long) get Download progress information Getbytesandstatus (long) Gets the download progress information and Status GetFileName (long) Gets the download file path GetURI (long) gets the download URI GetReason (long) Get download failure or pause reason Getpausedreason (long) Get download pause reason GetErrorCode (long) Get download error code source visible DOWNLOADMANAGERPRO.J Ava, more methods and more detailed parameters are presented in the visible Downloadmanagerpro Api guide.

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 execution execcommand (String command, Boolean isRoot) Shell environment executes the command source visible Shellutils.java, more methods and more detailed parameter description visible Shelluti ls Api Guide.

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 uninstall Issystemapplication (Context, String) to determine whether the application for the System application source visible Packageutils.java, more methods and more detailed parameters of the visible shellutils Api guide.

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 data Putint (context, string, int) holds the int type data getString (context, string) to get the String type data getInt (context, String) Gets the int type data can be modified by modifying the Preference_name variable preference name source visible Preferencesutils.java, more methods and more detailed parameters are described in the visible prefere Ncesutils Api Guide.

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) to get String type value string getString (String jsondata, String key, String defaultvalue) Gets the string type value representing the read from the JSON The value of a string type key

Getmap (Jsonobject jsonobject, String key) get map

Getmap (String jsondata, string key) gets a map indicating that the value of a map type key is read from JSON source code visible Jsonutils.java, more methods and more detailed parameters are visible jsonutil S API Guide.

8, FileUtils File tool class, can be used to read and write files and operation of the file. such as: ReadFile (string filePath) Read file WriteFile (string FilePath, String content, Boolean append) write file ge Tfilesize (string path) get File size DeleteFile (string path) Delete file source visible Fileutils.java, more methods and more detailed parameter description visible fileutils API Guide.

9, Resourceutils Android resource Tool class that can be used to read content from the raw and assets directories of the Android resource directory, such as: gefilefromassets (context context, String fileName) get asset s directory under a file content Gefilefromraw (context context, int resId) to get the raw directory of a file content source code visible Resourceutils.java, more methods and more detailed parameter introduction visible r Esourceutils Api Guide.

10, StringUtils         The String tool class, which can be used for common string operations, such as: IsEmpty (String str) to determine whether a string is empty or a length of 0 isBlank (string str) to determine whether a string is empty or a length of 0 or consists of spaces Utf8encode (string str) encoded in UTF-8 format capitalizefirstletter (string str) initial capital source visible Stringutils.java, more methods and more details Parameter description Visible StringUtils Api Guide.

11, Parcelutils

The Android Parcel tool class, which can be used to read from or write to a special type of data from Parcel, such as: Readboolean (Parcel in) reads the Boolean type data from Pacel readhashmap (Parcel In, ClassLoader Loader) reads the map type data from Pacel Writeboolean (Boolean B, Parcel out) to the Parcel to write the Boolean type data Writeha Shmap (map<k, v> map, Parcel out, int flags) write to Parcel Map type data source visible Parcelutils.java, more methods and more detailed parameter description visible parcelutils API Guide.

12, Randomutils random Number tool class, can be used to get fixed-size fixed word characters random number, such as: Getrandom (char[] sourcechar, int length) to generate a random string, all Characters are generated in a string getrandomnumbers (int length) to generate a random number of source visible Randomutils.java, more methods and more detailed parameters of the visible randomutils Api guide.

13, arrayutils Array tool class, 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[] So Urcearray, 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 Val UE, V DefaultValue, Boolean iscircle) get the next element of an element in the array, iscircle indicates whether the loop source is visible Arrayutils.java, more methods and more detailed parameters are shown arrayutils A Pi Guide.

14, Imageutils Picture Tool class, can be used for bitmap, byte array, drawable between conversion and image scaling, the current function is weak, will be enhanced later. such as: Bitmaptodrawable (Bitmap B) bimap convert to drawable drawabletobitmap (drawable D) drawable convert to Bitmap draw Abletobyte (drawable D) drawable convert to byte scaleimage (Bitmap org, float scalewidth, float scaleheight) Zoom image source Visible Imageutils.java, more methods and more detailed parameters are presented in the Imageutils Api Guide.

15, Listutils List Tool class, which can be used for list common operations, such as: IsEmpty (list<v> sourceList) to determine whether the list is empty or 0 joins (list<string> list, Str ing separator) list is converted to a string and Adddistinctentry (list<v> sourceList, V entry) is added to the list with a fixed delimiter to add the non-repeating element source visible L Istutils.java, more methods and more detailed parameters are presented in the Listutils Api Guide.

16, Maputils

The Map tool class, which can be used for map common operations, such as: IsEmpty (map<k, v> sourcemap) to determine whether a map is empty or a length of 0

Parsekeyandvaluetomap (string source, String keyandvalueseparator, String Keyandvaluepairseparator, Boolean Ignorespace) string parsing to map ToJson (map<string, string> map) map to JSON format source visible Maputils.java, more methods and more detailed parameter description visible Maputils Api Guide.

17, Objectutils The Object tool class, which can be used for object common operations, such as: Isequals (object actual, object expected) compare two objects for equality compare (v v1, v v2) compare two objects Large Small Transformintarray (int[] source) Integer array converted to int array source visible Objectutils.java, more methods and more detailed parameter description visible objectutils Api G Uide.

18. Serializeutils 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) to deserialize an object from a file Serialization (String FilePath, Object obj) serializes an object to a file source visible Serializeutils.java, more methods and more detailed parameters are presented in the visible serializeutils Api Guid E.

19, Systemutils System Information tool class, can be used to get the appropriate size of the thread pool, the current function is weak, will be enhanced later. such as: Getdefaultthreadpoolsize () to be consistent with the system configuration thread pool size source visible Systemutils.java, more methods and more detailed parameters of the Systemutils Api Guide can be seen.

20, Timeutils Time tool class, can be used for time-related operations, such as: Getcurrenttimeinlong () to get the current time getTime (long Timeinmill is, SimpleDateFormat DateFormat) converts a long to a fixed-format time string source visible Timeutils.java, more methods and more detailed parameters are presented in the Visual Timeutils Api Guide.

Android Development Common Tool class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.