Skip to content

Commit

Permalink
fix: opened files having unusable file names
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallahmehiz committed Aug 17, 2024
1 parent 1307702 commit 8c97613
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,12 @@ class PlayerActivity : AppCompatActivity() {
}

private fun getFileName(intent: Intent): String? {
if (intent.hasExtra(Intent.EXTRA_STREAM)) {
val uri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM)!!
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val cursor = contentResolver.query(uri, arrayOf(MediaStore.MediaColumns.DISPLAY_NAME), null, null)
if (cursor!!.moveToFirst()) return cursor.getString(0).also { cursor.close() }
}
val uri = (intent.data ?: intent.getParcelableExtra(Intent.EXTRA_STREAM))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && uri != null) {
val cursor = contentResolver.query(uri, arrayOf(MediaStore.MediaColumns.DISPLAY_NAME), null, null)
if (cursor?.moveToFirst() == true) return cursor.getString(0).also { cursor.close() }
}
return (intent.data ?: intent.getParcelableExtra(Intent.EXTRA_STREAM))
?.lastPathSegment
?.substringAfterLast('/')
return uri?.lastPathSegment?.substringAfterLast("/")
}

private fun resolveUri(data: Uri): String? {
Expand Down

0 comments on commit 8c97613

Please sign in to comment.