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.

Abx
  • 11
  • 1
  • Does [this](https://stackoverflow.com/q/58743541/9636037) help? – Abhimanyu Aug 23 '22 at 17:32
  • Is `getOriginalFileName` a function you have created? – Abhimanyu Aug 23 '22 at 17:32
  • Sorry paste prolem. I am updaing it @Abhimanyu – Abx Aug 24 '22 at 03: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...... – Abx Aug 24 '22 at 03:44
  • Thanks. So i should use ```val context = LocalContext.current``` LocalContext.current. – Abx Aug 24 '22 at 04:09
  • Btw on a side note, on this issue i wasted hours, i think. Why not post my problem if someone kind & alike minded who went through the same can help me and give importance/value to his as well as others time. No need to refigure out things which which has already been figured. – Abx Aug 24 '22 at 04:21
  • "Why not post my problem if someone kind & alike minded who went through the same can help me *within in a minute* and ........"* – Abx Aug 24 '22 at 04:30

0 Answers0