From c536bbb7e9105045349af5fc597bae9d5b1001de Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 22 Sep 2020 18:17:11 +0200 Subject: tv: account for broken TVs with no file picker Signed-off-by: Jason A. Donenfeld --- ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'ui/src/main/java/com/wireguard/android') diff --git a/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt b/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt index 7e3d425d..7b93f563 100644 --- a/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt +++ b/ui/src/main/java/com/wireguard/android/activity/TvMainActivity.kt @@ -5,6 +5,7 @@ package com.wireguard.android.activity +import android.content.ActivityNotFoundException import android.os.Bundle import android.util.Log import android.view.View @@ -31,6 +32,7 @@ import kotlinx.coroutines.launch class TvMainActivity : AppCompatActivity() { private val tunnelFileImportResultLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { data -> + if (data == null) return@registerForActivityResult lifecycleScope.launch { TunnelImporter.importTunnel(contentResolver, data) { Toast.makeText(this@TvMainActivity, it, Toast.LENGTH_LONG).show() @@ -98,7 +100,11 @@ class TvMainActivity : AppCompatActivity() { } } binding.importButton.setOnClickListener { - tunnelFileImportResultLauncher.launch("*/*") + try { + tunnelFileImportResultLauncher.launch("*/*") + } catch (e: ActivityNotFoundException) { + Toast.makeText(this@TvMainActivity, getString(R.string.tv_error), Toast.LENGTH_LONG).show() + } } binding.deleteButton.setOnClickListener { isDeleting.set(!isDeleting.get()) -- cgit v1.2.3