Java android 8+;上的MultipartPloadRequest上载失败(上载过程中出错);装置
我对多端口请求有问题。所有东西都在API较低的设备上运行,但当设备具有android 8或更高版本时,当我想将文件上传到服务器时,它会一直给我错误(“上传时出错”)。在安卓8的设备上,它开始发送,但当进度达到100%时,会出现错误(在安卓9的设备上,它甚至不会启动,开始上传时出错)。我认为这一切都是由于前台服务缺少通知造成的,但在我添加它时问题仍然发生 我看过类似的主题,比如这个(),但它对我没有帮助,因为我使用的是api 18-28,还有这个,但我已经有了这个权限 我的代码:Java android 8+;上的MultipartPloadRequest上载失败(上载过程中出错);装置,java,android,upload,okhttp,Java,Android,Upload,Okhttp,我对多端口请求有问题。所有东西都在API较低的设备上运行,但当设备具有android 8或更高版本时,当我想将文件上传到服务器时,它会一直给我错误(“上传时出错”)。在安卓8的设备上,它开始发送,但当进度达到100%时,会出现错误(在安卓9的设备上,它甚至不会启动,开始上传时出错)。我认为这一切都是由于前台服务缺少通知造成的,但在我添加它时问题仍然发生 我看过类似的主题,比如这个(),但它对我没有帮助,因为我使用的是api 18-28,还有这个,但我已经有了这个权限 我的代码: private
private void uploadMultipart(final Context context){
try{
MultipartUploadRequest uploadRequest = new MultipartUploadRequest(context,SERVER_URL)
.setUtf8Charset()
.setMethod("POST")
.setMaxRetries(0)
.setNotificationConfig(new UploadNotificationConfig())
.addFileToUpload(zipDir.getAbsolutePath()+"/"+emailAddress+".zip","file")
.setDelegate(new UploadStatusDelegate() {
@Override
public void onProgress(Context context, UploadInfo uploadInfo)
{
// Log.i("Progress", String.valueOf(uploadInfo.getProgressPercent()));
asyncResponse.returnProgress(uploadInfo.getProgressPercent());
}
@Override
public void onError(Context context, UploadInfo uploadInfo, ServerResponse serverResponse, Exception exception) {
// Log.i("error","error");
asyncResponse.returnHttpStatus(50);
}
@Override
public void onCompleted(Context context, UploadInfo uploadInfo, ServerResponse serverResponse) {
asyncResponse.returnHttpStatus(serverResponse.getHttpCode());
// Log.i("SEND DONE", String.valueOf(serverResponse.getHttpCode()));
}
@Override
public void onCancelled(Context context, UploadInfo uploadInfo) {
// Log.i("Progress","Cancelled");
}
});
.addParameter("email",emailAddress);
// For Android > 8, we need to set an Channel to the UploadNotificationConfig.
// So, here, we create the channel and set it to the MultipartUploadRequest
mNotificationManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
// Android O requires a Notification Channel.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "SPN";
// Create the channel for the notification
NotificationChannel mChannel =
new NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_DEFAULT);
// Set the Notification Channel for the Notification Manager.
mNotificationManager.createNotificationChannel(mChannel);
}
uploadRequest.startUpload();
}
catch (Exception e){
errorInSending=true;
}
}
我在asynctask中运行这个函数(在doInBackground函数中)。调用uploadRequest.startUpload()后代码>它将转到OneError
我正在使用这个lib()的3.4.2版本