mirror of
https://github.com/bitwarden/android.git
synced 2024-11-21 17:05:44 +03:00
PM-14480: Update IntentManager to be able to launch apps (#4233)
This commit is contained in:
parent
4930c1032e
commit
db3490f61a
1 changed files with 33 additions and 6 deletions
|
@ -6,6 +6,7 @@ import android.content.ActivityNotFoundException
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.IntentSender
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
@ -27,6 +28,7 @@ import com.x8bit.bitwarden.MainActivity
|
||||||
import com.x8bit.bitwarden.R
|
import com.x8bit.bitwarden.R
|
||||||
import com.x8bit.bitwarden.data.autofill.util.toPendingIntentMutabilityFlag
|
import com.x8bit.bitwarden.data.autofill.util.toPendingIntentMutabilityFlag
|
||||||
import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage
|
import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage
|
||||||
|
import com.x8bit.bitwarden.data.platform.util.isBuildVersionBelow
|
||||||
import com.x8bit.bitwarden.ui.platform.util.toFormattedPattern
|
import com.x8bit.bitwarden.ui.platform.util.toFormattedPattern
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.time.Clock
|
import java.time.Clock
|
||||||
|
@ -82,7 +84,7 @@ class IntentManagerImpl(
|
||||||
override fun startActivity(intent: Intent) {
|
override fun startActivity(intent: Intent) {
|
||||||
try {
|
try {
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
} catch (e: ActivityNotFoundException) {
|
} catch (_: ActivityNotFoundException) {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +117,7 @@ class IntentManagerImpl(
|
||||||
}
|
}
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
true
|
true
|
||||||
} catch (e: ActivityNotFoundException) {
|
} catch (_: ActivityNotFoundException) {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,12 +134,28 @@ class IntentManagerImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun launchUri(uri: Uri) {
|
override fun launchUri(uri: Uri) {
|
||||||
val newUri = if (uri.scheme == null) {
|
if (uri.scheme.equals(other = "androidapp", ignoreCase = true)) {
|
||||||
uri.buildUpon().scheme("https").build()
|
val packageName = uri.toString().removePrefix(prefix = "androidapp://")
|
||||||
|
if (isBuildVersionBelow(Build.VERSION_CODES.TIRAMISU)) {
|
||||||
|
startActivity(createPlayStoreIntent(packageName))
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
context
|
||||||
|
.packageManager
|
||||||
|
.getLaunchIntentSenderForPackage(packageName)
|
||||||
|
.sendIntent(context, Activity.RESULT_OK, null, null, null)
|
||||||
|
} catch (_: IntentSender.SendIntentException) {
|
||||||
|
startActivity(createPlayStoreIntent(packageName))
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
uri.normalizeScheme()
|
val newUri = if (uri.scheme == null) {
|
||||||
|
uri.buildUpon().scheme("https").build()
|
||||||
|
} else {
|
||||||
|
uri.normalizeScheme()
|
||||||
|
}
|
||||||
|
startActivity(Intent(Intent.ACTION_VIEW, newUri))
|
||||||
}
|
}
|
||||||
startActivity(Intent(Intent.ACTION_VIEW, newUri))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun shareText(text: String) {
|
override fun shareText(text: String) {
|
||||||
|
@ -301,6 +319,15 @@ class IntentManagerImpl(
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun createPlayStoreIntent(packageName: String): Intent {
|
||||||
|
val playStoreUri = "https://play.google.com/store/apps/details"
|
||||||
|
.toUri()
|
||||||
|
.buildUpon()
|
||||||
|
.appendQueryParameter("id", packageName)
|
||||||
|
.build()
|
||||||
|
return Intent(Intent.ACTION_VIEW, playStoreUri)
|
||||||
|
}
|
||||||
|
|
||||||
private fun getCameraFileData(): IntentManager.FileData {
|
private fun getCameraFileData(): IntentManager.FileData {
|
||||||
val tmpDir = File(context.filesDir, TEMP_CAMERA_IMAGE_DIR)
|
val tmpDir = File(context.filesDir, TEMP_CAMERA_IMAGE_DIR)
|
||||||
val file = File(tmpDir, TEMP_CAMERA_IMAGE_NAME)
|
val file = File(tmpDir, TEMP_CAMERA_IMAGE_NAME)
|
||||||
|
|
Loading…
Reference in a new issue