Skip to content

Commit

Permalink
Support for opening APK files from VIEW and SEND intent
Browse files Browse the repository at this point in the history
  • Loading branch information
soupslurpr committed Jan 8, 2024
1 parent 3c92154 commit acf5137
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:documentLaunchMode="intoExisting"
android:theme="@style/Theme.appverifier">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -31,6 +32,18 @@
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/vnd.android.package-archive" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />

<data android:scheme="content" />
<data android:mimeType="application/vnd.android.package-archive" />
</intent-filter>
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fun AppVerifierApp(
verifyAppViewModel: VerifyAppViewModel,
preferencesViewModel: PreferencesViewModel,
isActionSend: Boolean,
isActionView: Boolean,
) {
val verifyAppUiState = verifyAppViewModel.uiState.collectAsState()

Expand Down Expand Up @@ -92,7 +93,7 @@ fun AppVerifierApp(
) { innerPadding ->
NavHost(
navController = navController,
startDestination = if (isActionSend) {
startDestination = if (isActionSend || isActionView) {
AppVerifierScreens.VerifyApp.name
} else {
AppVerifierScreens.Start.name
Expand Down
28 changes: 25 additions & 3 deletions app/src/main/kotlin/dev/soupslurpr/appverifier/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.soupslurpr.appverifier

import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand Down Expand Up @@ -35,17 +36,37 @@ class MainActivity : ComponentActivity() {
val isActionSend =
(intent.action == Intent.ACTION_SEND)

val isActionView =
(intent.action == Intent.ACTION_VIEW)

if (isActionSend) {
val text = intent.getStringExtra(Intent.EXTRA_TEXT)
val extraText = intent.getStringExtra(Intent.EXTRA_TEXT)
val extraStream: Uri? = intent.getParcelableExtra(Intent.EXTRA_STREAM)

if (text != null) {
val verificationInfoText = verifyAppViewModel.getVerificationInfoText(text)
if (extraText != null) {
val verificationInfoText = verifyAppViewModel.getVerificationInfoText(extraText)

verifyAppViewModel.findAndSetAppVerificationInfoFromPackageName(
verificationInfoText.lines()[0],
packageManager
)
verifyAppViewModel.verifyFromText(verificationInfoText)
} else if (extraStream != null) {
verifyAppViewModel.setApkVerificationInfoAndInternalDatabaseStatusFromUri(
contentResolver,
extraStream,
packageManager
)
}
} else if (isActionView) {
if (intent.data != null) {
intent.data?.let {
verifyAppViewModel.setApkVerificationInfoAndInternalDatabaseStatusFromUri(
contentResolver,
it,
packageManager
)
}
}
}

Expand All @@ -62,6 +83,7 @@ class MainActivity : ComponentActivity() {
verifyAppViewModel = verifyAppViewModel,
preferencesViewModel = preferencesViewModel,
isActionSend = isActionSend,
isActionView = isActionView,
)
}
}
Expand Down

0 comments on commit acf5137

Please sign in to comment.