Usage and types of Android MimeType

Source: Internet
Author: User

Usage and types of Android MimeType

Mime type description

Multi-purpose Internet Mail Extension (MIME, Multipurpose Internet Mail Extensions) is an Internet standard that extends the email standard, it supports mail messages in multiple formats, such as non-ASCII characters and binary format attachments.

Content-Type. This header field is used to specify the message Type. Generally. [Type]/[subtype]

Type has the following format.

  • Text: indicates the standardized representation of Text information. Text messages can be in multiple character sets or formats;
  • Multipart: connects multiple parts of the message body to form a message. These parts can be different types of data;
  • Application: used to transmit Application data or binary data;
  • Message: Used to package an E-mail Message;
  • Image: used to transmit static Image data;
  • Audio: used to transmit Audio or Audio data;
  • Video: used to transmit dynamic image data. It can be a Video data format edited together with audio.

    Subtype is used to specify the type details. The set of content-type/subtype pairs and related parameters will increase over time. To ensure that these values are developed in an orderly and open state, MIME uses Internet Assigned Numbers Authority (IANA) as the central registration mechanism to manage these values. Common subtype values are as follows:

    • Text/plain (plain text)
    • Text/html (HTML document)
    • Application/xhtml + xml (XHTML document)
    • Image/gif (GIF image)
    • Image/jpeg (JPEG image) [image/pjpeg in PHP]
    • Image/png (PNG image) [image/x-png in PHP]
    • Video/mpeg (MPEG animation)
    • Application/octet-stream (any binary data)
    • Application/pdf (PDF)
    • Application/msword (Microsoft Word file)
    • Message/rfc822 (RFC 822 format)
    • Multipart/alternative (HTML form and plain text form of HTML mail, the same content is expressed in different forms)
    • Application/x-www-form-urlencoded (form submitted using the http post method)
    • Multipart/form-data (same as above, but mainly used when the form is submitted along with file upload) Upload )---------------------------------------------------------------------------------------------------------------------------

      Usage of MimeType in Android
      In Intent-FilterThere is a mimeType. Its function is to tell the Android system the type of files that the Activity can process. For example, if it is set to "text/plaindomain.txt", the file can be processed.
      MimeTypeMap class
      The MimeTypeMap class is a class dedicated to processing mimeType.

      Bytes ---------------------------------------------------------------------------------------------------------------------------
      Class description and method:

      [Java]View plaincopy
      1. Class Overview
      2. Two-way map that maps MIME-types to file extensions and vice versa.
      3. Summary
      4. Public Methods
      5. String
      6. GetExtensionFromMimeType (String mimeType)
      7. Return the registered extension for the given MIME type.
      8. Static String
      9. GetFileExtensionFromUrl (String url)
      10. Returns the file extension or an empty string iff there is no extension.
      11. String
      12. GetMimeTypeFromExtension (String extension)
      13. Return the MIME type for the given extension.
      14. StaticMimeTypeMap
      15. GetSingleton ()
      16. Get the singleton instance of MimeTypeMap.
      17. Boolean
      18. HasExtension (String extension)
      19. Return true if the given extension has a registered MIME type.
      20. Boolean
      21. HasMimeType (String mimeType)
      22. Return true if the given MIME type has an entry in the map. MimeTypeMap class is in singleton mode and has no public constructor. Use the getSinglton () method to obtain the MimeTypeMap object:
        MimeTypeMap mimeTypeMap = MimeTypeMap. getSingleton ();

        Example:

        [Java]View plaincopy
        1. Public class MainActivity extends Activity {
        2. Private String tag = "MainActivity ";
        3. @ Override
        4. Public void onCreate (Bundle savedInstanceState ){
        5. Super. onCreate (savedInstanceState );
        6. SetContentView (R. layout. main );
        7. System. out. println (111 );
        8. MimeTypeMap mimeTypeMap = MimeTypeMap. getSingleton ();
        9. // Check whether the MimeType of txt exists in MimeTypeMap
        10. System. out. println (mimeTypeMap. hasExtension ("txt "));
        11. System. out. println (mimeTypeMap. hasMimeType ("text/html "));
        12. // Obtain the MimeType of the txt file type
        13. String extension = mimeTypeMap. getMimeTypeFromExtension ("txt ");
        14. System. out. println (extension );
        15. }
        16. }

          Bytes ---------------------------------------------------------------------------------------------------------------------------
          In Android-4.2, the MimeUtils class is used to manage all supported MimeType types.[Java]View plaincopy
          1. Static {
          2. // The following table is based on/etc/mime. types data minus
          3. // Chemical/* MIME types and MIME types that don't map to any
          4. // File extensions. We also exclude top-level domain names
          5. // Deal with cases like:
          6. //
          7. // Mail.google.com/a/google.com
          8. //
          9. // And "active" MIME types (due to potential security issues ).
          10. Add ("application/andrew-inset", "ez ");
          11. Add ("application/dsptype", "tsp ");
          12. Add ("application/futuresplash", "spl ");
          13. Add ("application/hta", "hta ");
          14. ... Timeout ...---------------------------------------------------------------------------------------------------------------------------

            How to use:

            The instance code is the sample NotePad that comes with the SDK.

            StartActivity (new Intent (Intent. ACTION_EDIT, uri ));

            Uri: content: // com. google. provider. NotePad/notes/1

            The activity to be started is
            [Html]View plaincopy
            1. Android: theme = "@ android: style/Theme. Light"
            2. Android: label = "@ string/title_note"
            3. Android: screenOrientation = "sensor"
            4. Android: configChanges = "keyboardHidden | orientation"
            5. >

            6. How does the invisible Intent find its specific Activity?

              1. The system obtains the uri from intent and obtains content: // com. google. provider. NotePad/notes/1,

              Remove the starting content: identifier to get com. google. provider. NotePad/notes/1,

              Then retrieve com. google. provider. NotePad from the front, and go to Androidmanfest. xml.

              Find the provider whose authorities is com. google. provider. NotePad,

              Then load the content provider.
              [Java]View plaincopy
              1. Android: authorities = "com. google. provider. NotePad"
              2. />

                2. Call the gettype function of NotePadProvider and pass the above URI to this function,

                The function returns the type of the URI. Here, the return Notes. CONTENT_ITEM_TYPE indicates a log record,

                CONTENT_ITEM_TYPE = "vnd. android. cursor. item/vnd. google. note"

                [Java]View plaincopy
                1. @ Override
                2. Public String getType (Uri uri ){
                3. Switch (sUriMatcher. match (uri )){
                4. Case NOTES:
                5. Return Notes. CONTENT_TYPE;
                6. Case NOTE_ID:
                7. Return Notes. CONTENT_ITEM_TYPE;
                8. Default:
                9. Throw new IllegalArgumentException ("Unknown URI" + uri );
                10. }
                11. }

                  3. Then the system uses the obtained "vnd. android. cursor. item/vnd. google. note" and

                  "Android. intent. action. EDIT" to androidmanfest. xml to find the matching activity.

                  Android: authorities = "com. google. provider. NotePad" indicates the authorities of the ContentProvider,

                  Similar to the action in IntentFilter in activity, to put it bluntly, this ContentProvider is

                  The name in the android system. After the application is started,

                  It will always exist in the android system until the application is uninstalled.

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.