Detect selected file type in onActivityResult

107
May 05, 2022, at 10:10 AM

I'trying to open camera with video and photo.This code working correctly but in onActivityResult can't check file type. data.data is null Here is a code

private fun openCamera() {
    val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
    val takeVideoIntent = Intent(MediaStore.ACTION_VIDEO_CAPTURE)
    val chooserIntent = Intent(Intent.ACTION_CHOOSER)
    val contentSelectionIntent = Intent(Intent.ACTION_GET_CONTENT)
    val intentArray = arrayOf(takePictureIntent, takeVideoIntent)
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent)
    chooserIntent.putExtra(Intent.EXTRA_TITLE, "Choose an action")
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray)
    startActivityForResult(chooserIntent, CAMERA_STATUS_CODE)
}

onActivityResult code snippet

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    val selectedMediaUri = data?.data
    if (resultCode == RESULT_OK) {
        when (requestCode) {
            GALERY_STATUS_CODE -> {
                
            }
            CAMERA_STATUS_CODE -> {
                val path = data!!.data!!.path
                if (path!!.contains("/video/")) {
                   
                } else if (path.contains("/images/")) {
                    
                }
            }
        }
    }
}

what's a wrong in my code?! Thanks

Rent Charter Buses Company
READ ALSO
How do ensure the flutter app is working on all android devices out there?

How do ensure the flutter app is working on all android devices out there?

We have a flutter app on iOS and android and we test on 2 or 3 android devices before every release and it works fine without any issueBut when I see in the review, people are giving 1 star says that the app is not working for them

96
Missing programFiles/java when trying to publish rn app

Missing programFiles/java when trying to publish rn app

okay, when i wanna publish my reactNative app and see the docs i'm stuck on the first step

96
I am getting this issue, I tried using kotlin coroutines and Async still getting the same Calling this from Your main thread can lead to deadlock,

I am getting this issue, I tried using kotlin coroutines and Async still getting the same Calling this from Your main thread can lead to deadlock,

I also made another class that implements runnable to make a new thread still it's now working, Also tried with AynctaskAt last, I made a view model but still same issue

111
Android Manifest permissions issue

Android Manifest permissions issue

I have an app where im using uses-permission tags in the AndroidManifestxml to give some permissions to my app, eg CAMERA

131