Android Development Common Tool class

Source: Internet
Author: User
Tags response code

From http://www.open-open.com/lib/view/open1416535785398.html

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 networking tools classes, 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)
        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 the return content, HTTP response code, HTTP Expiration Time (Cache-control Max-age and expires), 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         You can use HttpURLConnection or Apache httpclient directly.
      Source visible Httputils.java, more methods and more detailed parameters are described in the visible httputils api guide.

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.iji Ami

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, such as: Install (Context, String) installation of the application, if the system is applied or has root, then install silently, otherwise general installation Uninstall (context, string) uninstall the application, if it is a system application or has root, then silently uninstall, otherwise general uninstall Issystemapplication (context, string) to determine whether the application for system application
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 for easy reading and writing of related type data to sharedpreferences such as: putstring (context, string, string)   Save String type data
        Putint (context, string, int)   Save int type data
        getString (context, string)   Get String type data
        GETINT (Context,  string)   Get int type data
        can modify Preference_name variable preference name
        Source visible Preferencesutils.java, more methods and more detailed parameters are described in the visible preferencesutils 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) 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
        File tool classes that can be used to read and write files and manipulate files. For example:
        ReadFile (string filepath)   read files
        WriteFile ( String filepath, string content, boolean append)   Write file
        GetFileSize (string path)   Get file size
        DeleteFile (string path)   Delete files
        Source code visible Fileutils.java, more methods and more detailed parameters are described in the visible fileutils api guide.

         9, resourceutils
        android  The 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)   Get a file content under assets directory
        Gefilefromraw (context  CONTEXT, INT RESID)   Get the contents of a file in raw directory
        Source visible Resourceutils.java, more methods and more detailed parameters of the visible resourceutils api guide.

        10, StringUtils
        String tool class that can be used for common string operations such as:
  & nbsp     IsEmpty (STRING STR)   Determine whether a string is empty or a length of 0
        IsBlank (STRING STR)   Determines whether the string is empty or 0  or consists of spaces
        Utf8encode (STRING STR)   encoded in UTF-8 format
        Capitalizefirstletter (STRING STR)   Initial capitalization
        Source visible Stringutils.java, more methods and more detailed parameters of the visible stringutils api guide.

       11, parcelutils
        Android parcel tool classes, Can be used to read or write special type data from Parcel, such as:
        Readboolean (parcel in)   Read Boolean data from Pacel
        Readhashmap (Parcel in, classloader loader)   reading map type data from Pacel
        Writeboolean (boolean b, parcel out)   Writing Boolean type data to Parcel
        Writehashmap (map<k, v> map, parcel out, int flags)   Writing map type data to parcel
        source visible Parcelutils.java, more methods and more detailed parameters are presented PARCELUTILS&NBSP;API  guide.

       12, randomutils
        Random number tool class, which can be used to obtain a random number of fixed-size fixed word characters, such as:
        Getrandom (char[] sourcechar, int length)   Generate random string, all characters nonspacing within a string
        getrandomnumbers (int length)   Generate random numbers
        Source visible Randomutils.java, more methods and more detailed parameters of the visible randomutils api guide.

       13, arrayutils
        Array tool classes for commonly used array operations such as:
    & nbsp   IsEmpty (V[] sourcearray)   Determine if the array is empty or 0
        GetLast (V[] sourcearray ,  v value, v defaultvalue, boolean iscircle)   Gets the first element of an element in the array, iscircle indicates whether to loop
        GetNext (v[] sourcearray, v value, v defaultvalue,  boolean iscircle)   Get 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 visible arrayutils api guide.

       14, imageutils
        Picture tool classes, available for bitmap, byte  Conversion between array, drawable and image scaling is currently weak and will be enhanced later. For example:
        bitmaptodrawable (bitmap b)  bimap convert to drawable
        Drawabletobitmap (drawable d)  drawable converted to bitmap
        Drawabletobyte ( DRAWABLE&NBSP;D)  drawable convert to byte
        Scaleimage (bitmap org, float  scalewidth, float scaleheight)   Zoom image
        Source visible Imageutils.java, more methods and more detailed parameters of the visible imageutils api guide.

         15, listutils
         list tool classes, available for list common operations such as:
        IsEmpty (list<v> sourcelist)   Determine if List is empty or length is 0
      & nbsp Join (List<string> list, string separator)  list is converted to a string and split with a fixed delimiter
        Adddistinctentry (list<v> sourcelist, v entry)   add non-repeating elements to the list
        Source Visible Listutils.java, more methods and more detailed parameters are described in the visible listutils api guide.

       16, maputils
        Map tool classes, which can be used for map common operations such as:
        IsEmpty (map<k, v> sourcemap)   Determine if the Map is empty or length 0                 Parsekeyandvaluetomap (string source, string keyandvalueseparator,  String keyandvaluepairseparator, boolean ignorespace)   string parsing to Map
ToJson (map<string, &NBSP;STRING>&NBSP;MAP)  map converted to JSON format
Source visible Maputils.java, more methods and more detailed parameters of the 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) 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.

Android Development Common Tool class

Related Article

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.