intent always containing null uri in compose

Viewed 12

im trying to retrieve file path. My code is-

fun Uri.getOriginalFileName(context: Context): String? {

val projection = arrayOf(
    MediaStore.Files.FileColumns.TITLE,
)

return context.contentResolver.query(this, projection, null, null, null)?.use {cursor ->
    val titleCol = cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.TITLE)
    cursor.moveToFirst()

    Log.i("TESTt", cursor.getString(titleCol))
    return cursor.getString(titleCol)
}
}

    
   



@Composable
    fun AppNotice() {
        Surface {
            Box {

        var path by remember { mutableStateOf("") }
      
        val intent = Intent(Intent.ACTION_GET_CONTENT)
        intent.type = "*/*"; ///
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        val context = LocalContext.current
        val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
            activityResult ->   if (activityResult.resultCode == RESULT_OK)
        {
            Log.d("appDebug", "oky")

             val uri = intent.getData()
            Log.d("uritest", "$uri")
            val name = uri?.getOriginalFileName(context)
            Log.d("seeFile", "$name")


             }

        else {
            Log.d("appDebug", "Denied")
        }
        }}

intent starts and upon selecting file yeild the same result, null. I cant figure out where is the problem. one thing to note is that, before i select a file its in null state

0 Answers
Related