mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-22 22:11:27 +01:00
add handler for ActivityNotFoundException
This commit is contained in:
parent
9f3142cb69
commit
f280d36667
4 changed files with 28 additions and 4 deletions
|
@ -3,6 +3,7 @@ package de.jrpie.android.launcher
|
|||
import android.app.Activity
|
||||
import android.app.Service
|
||||
import android.app.role.RoleManager
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
|
@ -16,6 +17,7 @@ import android.os.UserHandle
|
|||
import android.os.UserManager
|
||||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import de.jrpie.android.launcher.actions.Action
|
||||
import de.jrpie.android.launcher.actions.Gesture
|
||||
import de.jrpie.android.launcher.apps.AppInfo
|
||||
|
@ -90,7 +92,11 @@ fun getPrivateSpaceUser(context: Context): UserHandle? {
|
|||
fun openInBrowser(url: String, context: Context) {
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
intent.putExtras(Bundle().apply { putBoolean("new_window", true) })
|
||||
try {
|
||||
context.startActivity(intent)
|
||||
} catch (_: ActivityNotFoundException) {
|
||||
Toast.makeText(context, R.string.toast_activity_not_found_browser, Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
fun openTutorial(context: Context) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package de.jrpie.android.launcher.actions
|
|||
|
||||
import android.app.AlertDialog
|
||||
import android.app.Service
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.LauncherApps
|
||||
|
@ -34,7 +35,11 @@ class AppAction(val app: AppInfo) : Action {
|
|||
|
||||
context.packageManager.getLaunchIntentForPackage(packageName)?.let {
|
||||
it.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
try {
|
||||
context.startActivity(it)
|
||||
} catch (_: ActivityNotFoundException) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package de.jrpie.android.launcher.ui.list.apps
|
||||
|
||||
import android.content.ActivityNotFoundException
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.Fragment
|
||||
import de.jrpie.android.launcher.R
|
||||
import de.jrpie.android.launcher.apps.AppFilter
|
||||
|
@ -91,7 +93,16 @@ class ListFragmentApps : Fragment(), UIObject {
|
|||
|
||||
if (LauncherPreferences.functionality().searchWeb()) {
|
||||
val i = Intent(Intent.ACTION_WEB_SEARCH).putExtra("query", query)
|
||||
try {
|
||||
activity?.startActivity(i)
|
||||
} catch (_: ActivityNotFoundException) {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
R.string.toast_activity_not_found_search_web,
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
|
||||
} else {
|
||||
appsRecyclerAdapter.selectItem(0)
|
||||
}
|
||||
|
|
|
@ -328,5 +328,7 @@
|
|||
<string name="dialog_cancel">Cancel</string>
|
||||
<string name="settings_meta_licenses">Open Source Licenses</string>
|
||||
<string name="legal_info_title">Open Source Licenses</string>
|
||||
<string name="toast_activity_not_found_search_web">No app found to handle search.</string>
|
||||
<string name="toast_activity_not_found_browser">Can\'t open URL: no browser found.</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Reference in a new issue