-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add a workaround to open files on Android TV due to lack of SAF
- Loading branch information
Showing
5 changed files
with
122 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.amnezia.vpn | ||
|
||
import android.content.ActivityNotFoundException | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import org.amnezia.vpn.util.Log | ||
|
||
private const val TAG = "TvFilePicker" | ||
|
||
class TvFilePicker : ComponentActivity() { | ||
|
||
private val fileChooseResultLauncher = registerForActivityResult(ActivityResultContracts.GetContent()) { | ||
setResult(RESULT_OK, Intent().apply { data = it }) | ||
finish() | ||
} | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
Log.v(TAG, "onCreate") | ||
getFile() | ||
} | ||
|
||
override fun onNewIntent(intent: Intent) { | ||
super.onNewIntent(intent) | ||
Log.v(TAG, "onNewIntent") | ||
getFile() | ||
} | ||
|
||
private fun getFile() { | ||
try { | ||
Log.v(TAG, "getFile") | ||
fileChooseResultLauncher.launch("*/*") | ||
} catch (_: ActivityNotFoundException) { | ||
Log.w(TAG, "Activity not found") | ||
setResult(RESULT_CANCELED, Intent().apply { putExtra("activityNotFound", true) }) | ||
finish() | ||
} | ||
} | ||
} |