Android 9文件上传(MultipartUploadRequest)错误 [英] android 9 file upload (MultipartUploadRequest) error

查看:136
本文介绍了Android 9文件上传(MultipartUploadRequest)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目针对的是SDK27,并且运行良好且经过了严格的测试.由于Google Play想要定位到SDK28,因此我将定位更改为SDK28.

My project was targeting SDK27 and was working fine and heavily tested. Since google play want to target SDK28, I changed target to SDK28.

此后,我开始在(仅)Android 9中连接服务器时出现问题.由于服务器没有https(我的是一个小应用程序),因此这是clearTextTraffic禁用的问题.在AndroidManifest.xml中添加 android:usesCleartextTraffic ="true" 后,此问题已解决,应用程序再次像以前一样连接到服务器.

After this I started having issue connecting to server in (only) android 9. This turned out to be clearTextTraffic disabled issue as the server doesn't have https (mine is a small app). After adding android:usesCleartextTraffic="true"in AndroidManifest.xml, this issue was solved and app is again connecting to server as before.

我也有一个使用MultipartUploadRequest的图片上传页面,并且在SDK28之后也失败了,并且在android 9中仍然无法解决(它以前肯定可以正常工作,即使在其他android版本中也可以正常工作).因此,我几乎可以肯定这是与clearTextTraffic和文件上传有关的问题(或至少与targetSDK更改有关).但不确定如何解决此问题.我正在使用okhttp.任何帮助是极大的赞赏.

I also have an image upload page using MultipartUploadRequest and this was also failing after SDK28 and this is still not fixed in android 9 (it was definitely working before and is working fine even now in other android versions). So, I am almost sure this is clearTextTraffic and file upload related issue (or at least related with targetSDK change). But not sure what or how to solve this. I am using okhttp. Any help is greatly appreciated.

推荐答案

好吧,原来是FOREGROUND_SERVICE的android权限问题.

Ok, that turned out to be android permission issue with FOREGROUND_SERVICE.

定位到API Build.VERSION_CODES.P或更高版本的应用必须请求权限Manifest.permission.FOREGROUND_SERVICE才能使用此API.

Apps targeting API Build.VERSION_CODES.P or later must request the permission Manifest.permission.FOREGROUND_SERVICE in order to use this API.

解决方案是添加此行

< uses-permission android:name ="android.permission.FOREGROUND_SERVICE"/>

AndroidManifest.xml

详细答案此处

此外,如果由于您没有SSL证书而导致其他人遇到clearText错误问题,那么我们加密是一个无利可图的证书,它提供提供免费SSL证书的权限.在此处选中,然后这里.您可以在第二个链接中使用该软件轻松地应用和安装让我们在服务器中加密SSL证书.非常简单.

Also, if anyone else have the issue with clearText error since you don't have an SSL certificate, Let's encrypt is a no profit certificate providing authority that provides free SSL certificate. Check here and here. You can use the software in second link to easily apply and install Let's encrypt SSL certificates in your server. Very easy.

这篇关于Android 9文件上传(MultipartUploadRequest)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆