转载——解决小米miui系统调用系统裁剪图片功能camera.action.CROP后崩溃或重新打开app的问题

最近向做一个头像剪裁的功能,调用系统的gallery选择图片,用com.android.camera.action.CROP对URI剪裁便可以实现。
用联想的一部手机测试如下代码没问题
Java code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public  void  ChooseImage(View v) {
         Intent intent =  new  Intent(Intent.ACTION_GET_CONTENT); // ACTION_OPEN_DOCUMENT
         intent.addCategory(Intent.CATEGORY_OPENABLE);
         intent.setType( "image/*" );
         if  (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
             startActivityForResult(intent, SELECT_PIC_KITKAT);
         else  {
             startActivityForResult(intent, SELECT_PIC);
         }
     }
 
@Override
     public  void  onActivityResult( int  requestCode,  int  resultCode, Intent data) {
         if  (RESULT_OK == resultCode) {
             switch  (requestCode) {
             case  SELECT_PIC_KITKAT:
                 Uri selectedImage = data.getData();
                 startPhotoZoom(selectedImage);
                 break ;
             case  3 :
                 if (data !=  ){  
                     setPicToView(data);  
                 }
                 break ;
             default :
                 break ;
             }
         }
     }
 
public  void  startPhotoZoom(Uri uri) {
         Intent intent =  new  Intent( "com.android.camera.action.CROP" );
         intent.setDataAndType(uri,  "image/*" );
         intent.putExtra( "crop" "true" );
         intent.putExtra( "aspectX" 1 );
         intent.putExtra( "aspectY" 1 );
         intent.putExtra( "outputX" 150 );
         intent.putExtra( "outputY" 150 );
         intent.putExtra( "return-data" true );
         startActivityForResult(intent,  3 );
     }


但是小米系统下提示加载图片失败,去看了下log提示如下:
W/Worker  (18831): Exception in running a job
W/Worker  (18831): java.lang.SecurityException: Permission Denial: opening provider com.android.providers.media.MediaDocumentsProvider from ProcessRecord{43ca3940 18831:com.miui.gallery:crop/u0a6} (pid=18831, uid=10006) requires android.permission.MANAGE_DOCUMENTS or android.permission.MANAGE_DOCUMENTS
W/Worker  (18831):  at android.os.Parcel.readException(Parcel.java:1465)
W/Worker  (18831):  at android.os.Parcel.readException(Parcel.java:1419)
W/Worker  (18831):  at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2860)
W/Worker  (18831):  at android.app.ActivityThread.acquireProvider(ActivityThread.java:4448)
W/Worker  (18831):  at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:2239)
W/Worker  (18831):  at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1430)
W/Worker  (18831):  at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1052)
W/Worker  (18831):  at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:909)
W/Worker  (18831):  at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:766)
W/Worker  (18831):  at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:721)
W/Worker  (18831):  at com.miui.gallery.data.UriImage.openOrDownloadInner(UriImage.java:141)
W/Worker  (18831):  at com.miui.gallery.data.UriImage.openFileOrDownloadTempFile(UriImage.java:116)
W/Worker  (18831):  at com.miui.gallery.data.UriImage.prepareInputFile(UriImage.java:210)
W/Worker  (18831):  at com.miui.gallery.data.UriImage.access$100(UriImage.java:48)
W/Worker  (18831):  at com.miui.gallery.data.UriImage$BitmapJob.run(UriImage.java:233)
W/Worker  (18831):  at com.miui.gallery.data.UriImage$BitmapJob.run(UriImage.java:225)
W/Worker  (18831):  at com.miui.gallery.app.CropImageBase$LoadBitmapDataTask.run(CropImageBase.java:1003)
W/Worker  (18831):  at com.miui.gallery.app.CropImageBase$LoadBitmapDataTask.run(CropImageBase.java:975)
W/Worker  (18831):  at com.miui.gallery.util.ThreadPool$Worker.run(ThreadPool.java:130)
W/Worker  (18831):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
W/Worker  (18831):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
W/Worker  (18831):  at java.lang.Thread.run(Thread.java:841)
W/Worker  (18831):  at com.miui.gallery.util.PriorityThreadFactory$1.run(PriorityThreadFactory.java:43)

猜测调用com.android.camera.action.CROP实际为com.miui.gallery:crop缺少权限。

你可能感兴趣的:(转载——解决小米miui系统调用系统裁剪图片功能camera.action.CROP后崩溃或重新打开app的问题)