Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 改型2的作用域存储视频上载问题(java.io.FileNotFoundException:打开失败:eNot(无此类文件或目录)_Android_Kotlin_Android 10.0 - Fatal编程技术网

Android 改型2的作用域存储视频上载问题(java.io.FileNotFoundException:打开失败:eNot(无此类文件或目录)

Android 改型2的作用域存储视频上载问题(java.io.FileNotFoundException:打开失败:eNot(无此类文件或目录),android,kotlin,android-10.0,Android,Kotlin,Android 10.0,我想上传视频使用改型在API级别Q和更高 我创建了一个媒体助手,它给我一个图像和视频文件列表 return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { val collectionWithPending = MediaStore.setIncludePending(collection) CursorLoader(context, collectionWithPending, projection, selec

我想上传视频使用改型在API级别Q和更高

  • 我创建了一个媒体助手,它给我一个图像和视频文件列表

    return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        val collectionWithPending = MediaStore.setIncludePending(collection)
        CursorLoader(context, collectionWithPending, projection, selection, null, sortOrder)
    } else {
        CursorLoader(context, collection, projection, selection, null, sortOrder)
    }
    
  • 媒体加载工作正常:openFileDescriptor

               image.context.contentResolver.openFileDescriptor(mData.contentUri!!, FILE_OPEN_READ_MODE).use {
                image.setPicture(mData.contentUri, RequestOptions().placeholder(R.color.white).error(R.color.white).diskCacheStrategy(DiskCacheStrategy.NONE))
            }
    
  • 我尝试过两种不同的方法:

  • 路径:/storage/emulated/0/Pictures/1568101688613.jpg。它给了我一个错误拒绝开放访问
  • 内容uri为:content://media/external/video/media/78。它给了我一个错误java.io.FileNotFoundException:content:/media/external/video/media/78:open失败:enoint(没有这样的文件或目录)
  • 我正在使用改型上传视频

    inline fun <reified T : Any>getRetrofit(): T {
    val retrofit = Retrofit.Builder()
        .client(getDefaultClient())
        .baseUrl(BASE_URL)
        .addConverterFactory(getCustomConverterFactory())
        .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
        .build()
    
    return retrofit.create(T::class.java)}
    
    //Api call Interface
    interface UploadImagesRetrofitService {
        @Multipart
        @POST(MEDIA)
        fun getUploadMedia(
            @Header(ID) xID: String? = null,
            @Header(MEDIA_TYPE) mediaType: String? = null,
            @Header(UPLOAD_TYPE) uploadType: String? = null,
            @Part files: MultipartBody.Part
        ): Observable<UploadMediaResponse>
    }
    
    //Access the Interface
    fun getMediaUpload(xID: String, mediaType: String, uploadType: String, files: MultipartBody.Part): Observable<UploadMediaResponse> {
        return getRetrofitServiceTTU<UploadImagesRetrofitService>().getUploadMedia(xID, mediaType, uploadType, files)
    }
    
     fun getUpload(xID: String, mediaType: String, uploadType: String, files: MultipartBody.Part, height: Int = 0, width: Int = 0) {
    
        addDisposable(repo.getMediaUpload(xID, mediaType, uploadType, files).subscribeOn(Schedulers.io()).observeOn(Schedulers.io()).subscribe({
            if (it != null && it.reponseCode == 0) {
                it.height = height
                it.width = width
                it.mediaType = mMediaType
                mUploadingInterFace.getSuccessResponse(it)
            } else {
                mUploadingInterFace.getErrorResponse(it.responseError)
            }
        }, { thr ->
            thr.printStackTrace()
            if ((mContext?.isValid() == true) && mContext is BaseActivity) mContext.showError(mContext.getString(R.string.error_upload_media))
        }))
    }