Fix launch application #996

This commit is contained in:
J-Jamet
2021-08-27 13:32:41 +02:00
parent d290259075
commit 1bf912d6f0
3 changed files with 19 additions and 3 deletions

View File

@@ -239,8 +239,23 @@ object UriUtil {
}
fun openExternalApp(context: Context, packageName: String) {
var launchIntent: Intent? = null
try {
context.startActivity(context.applicationContext.packageManager.getLaunchIntentForPackage(packageName))
launchIntent = context.packageManager.getLaunchIntentForPackage(packageName)?.apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
} catch (ignored: Exception) {
}
try {
if (launchIntent == null) {
context.startActivity(
Intent(Intent.ACTION_VIEW)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.setData(Uri.parse("https://play.google.com/store/apps/details?id=$packageName"))
)
} else {
context.startActivity(launchIntent)
}
} catch (e: Exception) {
Log.e(TAG, "App cannot be open", e)
}

View File

@@ -138,11 +138,11 @@ class TextFieldView @JvmOverloads constructor(context: Context,
when {
labelView.text.contains(APPLICATION_ID_FIELD_NAME) -> {
val packageName = valueView.text.toString()
if (UriUtil.isExternalAppInstalled(context, packageName)) {
// TODO #996 if (UriUtil.isExternalAppInstalled(context, packageName)) {
valueView.customLink {
UriUtil.openExternalApp(context, packageName)
}
}
//}
}
else -> {
LinkifyCompat.addLinks(valueView, Linkify.WEB_URLS or Linkify.EMAIL_ADDRESSES)

View File

@@ -41,6 +41,7 @@
app:layout_constraintTop_toBottomOf="@+id/entry_field_label"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/entry_field_show"
android:textIsSelectable="true"
tools:text="value"
style="@style/KeepassDXStyle.TextAppearance.TextEntryItem" />
<androidx.appcompat.widget.AppCompatImageButton