android: do not crash on Browse button if activity wasn't found

This commit is contained in:
Alibek Omarov
2025-03-20 02:44:37 +03:00
parent 66bdca63ee
commit c389736c2f
2 changed files with 14 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package su.xash.engine.ui.library
import android.annotation.SuppressLint
import android.content.Intent
import android.content.ActivityNotFoundException
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
@@ -10,6 +11,7 @@ import android.view.MenuInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.view.MenuProvider
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
@@ -73,11 +75,16 @@ class LibraryFragment : Fragment(), MenuProvider {
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
when (menuItem.itemId) {
R.id.action_browse -> {
startActivity(
Intent(Intent.ACTION_VIEW).setDataAndType(
null, "vnd.android.document/directory"
try {
startActivity(
Intent(Intent.ACTION_VIEW).setDataAndType(
null, "vnd.android.document/directory"
)
)
)
}
catch(e: ActivityNotFoundException) {
Toast.makeText(getActivity(), R.string.library_fragment_no_file_manager, Toast.LENGTH_LONG).show()
}
}
R.id.action_install -> {
@@ -91,4 +98,4 @@ class LibraryFragment : Fragment(), MenuProvider {
return false
}
}
}

View File

@@ -33,4 +33,5 @@
<string name="preferences_client_package">Client package</string>
<string name="preferences_server_package">Server package</string>
<string name="preferences_use_icons">Use icons instead of backgrounds</string>
</resources>
<string name="library_fragment_no_file_manager">File manager is missing</string>
</resources>