Camera multiple files upload not working RocketWeb Android

After buying from CodeCanyon I configure the app, everything was working fine but can’t upload multiple images.

Update this line of code will solve the issue:

if (checkPermission(PERMISSIONS_REQUEST_CAMERA, true) &&
        checkPermission(PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE, true)) {
    if (PreferenceUtils.getInstance().getBooleanValue(Constants.KEY_FILE_UPLOAD_ENABLE, true)) {
        if (mFilePath != null) {
            mFilePath!!.onReceiveValue(null)
        }
        mFilePath = filePathCallback
        var takePictureIntent: Intent? = null

        if (PreferenceUtils.getInstance().getBooleanValue(Constants.KEY_PHOTO_UPLOAD_ENABLE, true)) {
            takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
            if (takePictureIntent.resolveActivity(this@HomeActivity.packageManager) != null) {
                var photoFile: File? = null
                try {
                    photoFile = createImageFile()
                    takePictureIntent.putExtra("PhotoPath", mFileCamMessage)
                } catch (ex: IOException) {
                    Log.e(TAG, "Image file creation failed", ex)
                }

                if (photoFile != null) {
                    mFileCamMessage = "file:" + photoFile.absolutePath
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile))
                } else {
                    takePictureIntent = null
                }
            }
        }

        val contentSelectionIntent = Intent(Intent.ACTION_GET_CONTENT)

        if (PreferenceUtils.getInstance().getBooleanValue(Constants.KEY_MULTIPLE_FILE_UPLOAD_ENABLE, false)) {
            contentSelectionIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
            contentSelectionIntent.type = "*/*"
        }

        if (PreferenceUtils.getInstance().getBooleanValue(Constants.KEY_CAMERA_PHOTO_UPLOAD_ENABLE, false)) {
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE)
            contentSelectionIntent.type = "image/*"
        }

        val intentArray: Array<Intent?>
        if (takePictureIntent != null) {
            intentArray = arrayOf(takePictureIntent)
        } else {
            intentArray = arrayOfNulls(0)
        }

        val chooserIntent = Intent(Intent.ACTION_CHOOSER)
        chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent)
        chooserIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.label_file_chooser))
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray)
        startActivityForResult(chooserIntent, FILE_CHOOSER)
        return true
    } else {
        return false
    }
}
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
    super.onActivityResult(requestCode, resultCode, intent)

    if (requestCode == REQUEST_CODE_IMMEDIATE_UPDATE) {
        when (resultCode) {
            Activity.RESULT_OK -> {
                UtilMethods.showLongToast(mContext, "Application update successfully!")
            }
            Activity.RESULT_CANCELED -> {
                UtilMethods.showLongToast(mContext, "Application update is mandatory!")
            }
            ActivityResult.RESULT_IN_APP_UPDATE_FAILED -> {
                UtilMethods.showLongToast(mContext, "Application update is mandatory!")
            }
        }
    }

    if (Build.VERSION.SDK_INT >= 21) {
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
        window.statusBarColor = resources.getColor(R.color.colorPrimary)
        var results: Array<Uri>? = null
        if (resultCode == Activity.RESULT_OK) {
            if (requestCode == FILE_CHOOSER) {
                if (mFilePath == null) {
                    return
                }
                if (intent == null || intent.data == null) {
                    if (mFileCamMessage != null) {
                        results = arrayOf(Uri.parse(mFileCamMessage))
                    }
                } else {
                    val dataString = intent.dataString
                    if (intent.clipData != null) {
                        val numSelectedFiles: Int = intent.clipData?.itemCount?: 0
                        results = Array(numSelectedFiles) { Uri.EMPTY}
                        for (i in 0 until numSelectedFiles) {
                            results[i] = intent.clipData!!.getItemAt(i).uri
                        }
                    }else if (dataString != null) {
                        results = arrayOf(Uri.parse(dataString))
                    }else{
                        UtilMethods.printLog(TAG, "Image upload data is empty!")
                    }
                }
            }
        }
        mFilePath!!.onReceiveValue(results)
        mFilePath = null
    } else {
        if (requestCode == FILE_CHOOSER) {
            if (null == mFileMessage) return
            val result = if (intent == null || resultCode != Activity.RESULT_OK) null else intent.data
            mFileMessage?.onReceiveValue(result)
            mFileMessage = null
        }
    }
}

2 thoughts on “Camera multiple files upload not working RocketWeb Android

Leave a Reply