[Android] OTG: fix crash when OTG activity doesn't exist
Geoffrey Métais
git at videolan.org
Tue Jan 8 11:26:55 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan 7 17:48:48 2019 +0100| [4ccc60641066504b76cb9ff404040deb6eb119db] | committer: Geoffrey Métais
OTG: fix crash when OTG activity doesn't exist
> https://code.videolan.org/videolan/vlc-android/commit/4ccc60641066504b76cb9ff404040deb6eb119db
---
.../src/org/videolan/vlc/gui/helpers/hf/OtgAccess.kt | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/OtgAccess.kt b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/OtgAccess.kt
index 3f980f5d1..4e0f552e5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/hf/OtgAccess.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/hf/OtgAccess.kt
@@ -20,15 +20,16 @@
package org.videolan.vlc.gui.helpers.hf
-import androidx.lifecycle.LiveData
+import android.annotation.TargetApi
+import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import android.net.Uri
+import android.os.Build
import android.os.Bundle
-import androidx.annotation.WorkerThread
-import androidx.fragment.app.FragmentActivity
-import androidx.documentfile.provider.DocumentFile
import android.util.Log
+import androidx.annotation.WorkerThread
+import androidx.lifecycle.LiveData
import org.videolan.medialibrary.media.MediaWrapper
import videolan.org.commontools.LiveEvent
@@ -38,12 +39,17 @@ const val TAG = "OtgAccess"
const val OTG_CONTENT_AUTHORITY = "com.android.externalstorage.documents"
const val OTG_SCHEME = "otg"
+ at TargetApi(Build.VERSION_CODES.LOLLIPOP)
class OtgAccess : BaseHeadlessFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val safIntent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
- startActivityForResult(safIntent, SAF_REQUEST)
+ try {
+ startActivityForResult(safIntent, SAF_REQUEST)
+ } catch (e: ActivityNotFoundException) {
+ exit()
+ }
}
override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
More information about the Android
mailing list