0

Here is my code

fun Uri.getOriginalFileName(context: Context): String? {
    return context.contentResolver.query(this, null, null, null, null)?.use {
        val nameColumnIndex = it.getColumnIndex(OpenableColumns.DISPLAY_NAME)
        it.moveToFirst()
        it.getString(nameColumnIndex)
    }
}


@Composable
fun AppNotice() {
    
            val intent = Intent(Intent.ACTION_GET_CONTENT)
            intent.type = "*/*"; ///
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
                activityResult ->   if (activityResult.resultCode == RESULT_OK)
            {
                Log.d("appDebug", "oky")
                var uri = intent.getData()
                val name: String? = uri?.getOriginalFileName(Context)
                Log.d("seeFile", "$name")
                 }

            else {
                Log.d("appDebug", "Denied")
            }
Button(onClick={launcher.launch(intent)})
{Text("Button")}
            }

Context is a class then how to know what method will i need in this line/context name: String? = uri?.getOriginalFileName(Context)

I went to adroid.dev page but found a huge page and cant figure out what i need since saw only few uri permission related stuffs.

7
  • Does this help? Commented Aug 23, 2022 at 17:32
  • Is getOriginalFileName a function you have created? Commented Aug 23, 2022 at 17:32
  • Sorry paste prolem. I am updaing it @Abhimanyu Commented Aug 24, 2022 at 3:43
  • Well i got your point@RichardOnslowRoper. Do you know of any site which is of college level? I tried Stackover Chat but thhere is reputation requirement...... Commented Aug 24, 2022 at 3:44
  • Thanks. So i should use val context = LocalContext.current LocalContext.current. Commented Aug 24, 2022 at 4:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.