简体   繁体   English

图片上传仅适用于小米手机

[英]Image upload not working only in Mi mobiles

This is the error i am getting when i am trying to upload the image from Mi mobile.But for other phones it working fine这是我尝试从 Mi 手机上传图像时遇到的错误。但对于其他手机,它工作正常

java.lang.RuntimeException: Failure delivering result 
ResultInfo{who=null, request=1, result=-1, data=Intent { flg=0x1 clip={image/* text/uri-list U:content://com.miui.gallery.open/raw/%2Fstorage%2Femulated%2F0%2FDCIM%2FCamera%2FIMG_20171107_230239.jpg} (has extras) }} to activity {com.fullstacknet.chatapp/com.fullstacknet.chatapp.ChatActivity}: 
java.lang.IllegalArgumentException: Invalid URI: content://com.miui.gallery.open/raw/%2Fstorage%2Femulated%2F0%2FDCIM%2FCamera%2FIMG_20171107_230239.jpg
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4108)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4151)
    at android.app.ActivityThread.-wrap20(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1551)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6195)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764)
Caused by: java.lang.IllegalArgumentException: Invalid URI: content://com.miui.gallery.open/raw/%2Fstorage%2Femulated%2F0%2FDCIM%2FCamera%2FIMG_20171107_230239.jpg
    at android.provider.DocumentsContract.getDocumentId(DocumentsContract.java:917)
    at com.fullstacknet.chatapp.ChatActivity.getRealPathFromURI(ChatActivity.java:896)
    at com.fullstacknet.chatapp.ChatActivity.onActivityResult(ChatActivity.java:962)
    at android.app.Activity.dispatchActivityResult(Activity.java:6998)
    at android.app.ActivityThread.deliverResults(ActivityThread.java:4104)
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:4151) 
    at android.app.ActivityThread.-wrap20(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1551) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:154) 
    at android.app.ActivityThread.main(ActivityThread.java:6195) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:874) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:764) 
    11-08 13:38:59.261 28831-28831/com.fullstacknet.chatapp E/MQSEventManagerDelegate: failed to get MQSService.

I'm selecting the image using this Intent:我正在使用此 Intent 选择图像:

 Intent intent = new Intent();
 intent.setType("image/*");
 intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
 intent.setAction(Intent.ACTION_GET_CONTENT);
 startActivityForResult(Intent.createChooser(intent,"Select Picture"), 1);

It is not hitting the onActivityResult after selecting the image.选择图像后它没有点击onActivityResult Any ideas on how I can resolve this issue?关于如何解决此问题的任何想法?

If you see the URI in the log如果您在日志中看到 URI

URI: content://com.miui.gallery.open/raw/%2Fstorage%2Femulated%2F0%2FDCIM%2FCamera%2FIMG_20171107_230239.jpg

here %2F is not properly decoded此处%2F未正确解码

It should be something like this:它应该是这样的:

content://com.miui.gallery.open/raw//storage/emulated/0/DCIM/Camera/IMG_20171107_230239.jpg

But I still don't think it will work because it is customized.但我仍然不认为它会起作用,因为它是定制的。

Better to return /storage/emulated/0/DCIM/Camera/IMG_20171107_230239.jpg as the actual path and then get the URI if you want.最好返回/storage/emulated/0/DCIM/Camera/IMG_20171107_230239.jpg作为实际路径,然后根据需要获取 URI。

that`s the solution , the key word ws这就是解决方案,关键词ws

   private boolean corp(Activity activity, Uri uri, boolean fromCamera) {
        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        if (fromCamera){
            cropIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        }
       ...

https://blog.csdn.net/weixin_40087231/article/details/89467708 https://blog.csdn.net/weixin_40087231/article/details/89467708

The perfect solution is, Add below entities in your manifest file完美的解决方案是,在清单文件中添加以下实体

android:hardwareAccelerated="false"

android:largeHeap="true"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM