Android System compatibility issues (continuous update)

Source: Internet
Author: User

believe that the development of an android has been the compatibility of Android issues to toss over, and sometimes it is very helpless, Android by different manufacturers to change the pieces. This article mainly summarizes the actual project development process I encountered in the compatibility problems, as well as the final solution. This article will be updated continuously.

1. System crash (null pointer exception) in HTC 7 when selecting a System album System version 2.3.7

Recently in the function of publishing, you need to select a picture from the system album, and finally upload this image to the server. You usually choose a picture from the system album as follows:

Albumbutton.setonclicklistener (new  View.onclicklistener () {    @Override    public void OnClick (View v) {        new  Intent (Intent.action_pick, Android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);        Startactivityforresult (Intent, Appcontext.getimage_bysdcard);    });

Then get the photo you just picked in Onactivityresult:

1 @Override2 protected voidOnactivityresult (intRequestcode,intResultCode, Intent Intent) {3     if(ResultCode = =RESULT_OK) {4         if(Requestcode = = Appcontext.getimage_bysdcard | | requestcode = =Appcontext.getimage_bycamera) {5             if(Requestcode = = Appcontext.getimage_bysdcard &&NULL!=data) {6Uri SelectedImage =Data.getdata ();7string[] Filepathcolumn ={MediaStore.Images.Media.DATA};8cursor cursor = getcontentresolver (). Query (SelectedImage, Filepathcolumn,NULL,NULL,NULL);9                 if(Cursor! =NULL) {Ten                     if(Cursor.movetofirst ()) { One                         //int columnindex = Cursor.getcolumnindex (filepathcolumn[0]); A                         intColumnIndex = Cursor.getcolumnindexorthrow (filepathcolumn[0]); -Photopath =cursor.getstring (columnindex); -                     } the cursor.close (); -                 } -             } -         } +     } -}

Can be found on the HTC7 2.3.7 cannot get the picture, if the above code does not do cursor! = NULL The system crashes, and finally the reason is that the URI selectedimage = Data.getdata (); This line of code, on other phones, The return format here is content://media/external/images/media/244709, so it is natural to get the actual address of the picture through the next content Privider method. On HTC This phone, the return result is:/storage/sdcard0/dcim/camera/img_20140608_162447.jpg, that is, directly return the address of the selected picture, therefore, you need to make the following processing:

1 @Override2 protected voidOnactivityresult (intRequestcode,intResultCode, Intent Intent) {3     if(ResultCode = =RESULT_OK) {4         if(Requestcode = = Appcontext.getimage_bysdcard | | requestcode = =Appcontext.getimage_bycamera) {5             if(Requestcode = = Appcontext.getimage_bysdcard &&NULL!=data) {6Uri SelectedImage =Data.getdata ();7string[] Filepathcolumn ={MediaStore.Images.Media.DATA};8cursor cursor = getcontentresolver (). Query (SelectedImage, Filepathcolumn,NULL,NULL,NULL);9                 if(Cursor! =NULL) {Ten                     if(Cursor.movetofirst ()) { One                         //int columnindex = Cursor.getcolumnindex (filepathcolumn[0]); A                         intColumnIndex = Cursor.getcolumnindexorthrow (filepathcolumn[0]); -Photopath =cursor.getstring (columnindex); -                     } the cursor.close (); -}Else { -                     if(SelectedImage! =NULL) { -String Tmppath =Selectedimage.getpath (); +                         if(Tmppath! =NULL&& (Tmppath.endswith (". jpg") | | tmppath.endswith (". png") | | tmppath.endswith (". gif")))) { -Photopath =Tmppath; +                         } A                     } at                 } -             } -         } -     } -}

----------------------------

One day to tidy up a little update ...

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.