Android Development Trivia Point (ii)

Source: Internet
Author: User

1.android Studio in the log console, showing no debuggable applications, there is no way to debug a program separately, you can tools->android->enable ADB integration Active.

2. Select a picture from the album

After 4.4 It is not recommended to use the action:intent.action_get_content&nbsp  , but to use//intent.action_open_document, The corresponding subsequent processing will also have some changes, code as follows//open the Picture Viewer to select the picture, you can call the following methods in the Click event  ,requestCode  can define a variable request_code_for_select_ Picture = 0x001;     public static void selectpictrue ( Activity activity, int requestcode)  {        try  {            //Open the album in your phone              if  (build.version.sdk_int <  Build.version_codes. KITKAT)  {//SDK  Under 19                  intent intent = new intent ();                 intent.settype ("image/*");           &Nbsp;     intent.setaction (intent.action_get_content);                 activity.startactivityforresult ( Intent.createchooser (Intent, activity.getresources (). getString (R.string.chat_activity_select_picture)),  requestcode);             } else {/ /sdk  over 19                  intent intent = new intent (intent.action_open_document);                 intent.addcategory (Intent.CATEGORY_ openable);                 Intent.settype ("image/*");                 activity.startactivityforresUlt (Intent, requestcode);            }         } catch  (exception e)  {             e.printstacktrace ();             toastutils.showlongtoast ("Picture file Viewer failed to start");         }    }////////////////////after obtaining the URI of the image  onActivityResult  The processing of the method will be somewhat different, the code is as follows &NBSP, and then in the activity of the onactivityresult  method down with the following method, you can get the path of the image  /////////////////////// @TargetApi (build.version_codes. KITKAT)     public static string onactivityresult (Activity activity,  int requestcode, int resultcode, intent data)  {         if  (RESULTCODE&NBSP;==&NBSP;ACTIVITY.RESULT_OK) &NBSP;{&NBSP;&NBSP;&NBSP;&NBSP;&Nbsp;       try {                 String tempPath = null;        if  (requestcode == request_code_for_select_picture)  {  //judgment   Do you want to choose a picture from the album                      if  (data == null)  {                          Toastutils.showlongtoast ("The operation failed, please try again ...");                         return null;                     }                     uri uri =  null;                     //SDK  less than 19                     if  (Build.version.sdk_int < build.version_ CODES. KITKAT)  {                         uri = data.getdata ();                     } else {  //SDK  Greater than  19                         //for Android 4.4                         uri  = data.getdata ();                         int takeflags = intent.flag_ grant_read_uri_permission | intent.flag_grant_write_uri_permission;                          activity.getcontentresolver (). Takepersistableuripermission (uri, takeflags);                     }                      Temppath = providerpathutils.getpath (Activity, uri);                 }                 if  (Textutils.isempty (temppath))  {                     toastutils.showlongtoast ("The operation failed, please try again ...");                      return null;                 }                &NBSP;LOGGER.E ("Image path ="  + temppath);                 return tempPath;             } catch  (exception e)  {             &Nbsp;   e.printstacktrace ();             }        }        return  null;    }

3. Displaying HTML effects in TextView (reference http://blog.csdn.net/dawanganban/article/details/11191265)

textview tv= (TextView) Findviewbyid (r.id.textview1);           string html= " 

4.GridView or ListView using Android:cliptopadding= "false" can be set padding value, so that its settings padding applied to the parent layout, sliding up and down, there will not be set padding margins, See http://blog.csdn.net/hpu_zyh/article/details/44520949 for details.

5.intent transfer pictures, the size of the picture object should not exceed 40K, otherwise it will be reported!!! Failed Binder transation!!!

6. Limit the input length of the EditText, for example: MaxLength = "3"


Android Development Trivia Point (ii)

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.