Skip to content

Commit 82f71be

Browse files
committed
Fix Apk install (fix #200)
1 parent f7c034a commit 82f71be

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
88
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="32"/>
99
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
10-
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" /> <!-- Needed to prompt the user to give permission to install a downloaded apk -->
11-
<uses-permission-sdk-23 android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
10+
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
11+
<uses-permission-sdk-23 android:name="android.permission.REQUEST_INSTALL_PACKAGES" /> <!-- Needed to prompt the user to give permission to install a downloaded apk -->
1212

1313
<uses-feature
1414
android:name="android.hardware.wifi"

app/src/main/java/com/fmsys/snapdrop/MainActivity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,11 @@ public void onCompleted(@NonNull final Object file) {
633633

634634
private void fileDownloadedIntent(final Uri uri, final JavaScriptInterface.FileHeader fileHeader) {
635635
final int notificationId = (int) SystemClock.uptimeMillis();
636+
boolean isApk = fileHeader.getName().toLowerCase().endsWith(".apk");
636637

637638
final Intent intent = new Intent();
638-
intent.setAction(Intent.ACTION_VIEW);
639-
intent.setDataAndType(uri, fileHeader.getMime());
639+
intent.setAction(isApk ? Intent.ACTION_INSTALL_PACKAGE : Intent.ACTION_VIEW);
640+
intent.setDataAndType(uri, isApk ? "application/vnd.android.package-archive" : fileHeader.getMime());
640641
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
641642

642643
final PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 1, intent, Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_CANCEL_CURRENT : PendingIntent.FLAG_CANCEL_CURRENT);
@@ -674,7 +675,7 @@ private void fileDownloadedIntent(final Uri uri, final JavaScriptInterface.FileH
674675
}
675676

676677
final Snackbar snackbar = Snackbar.make(binding.pullToRefresh, R.string.download_successful, Snackbar.LENGTH_LONG)
677-
.setAction(R.string.open, button -> {
678+
.setAction(isApk ? R.string.install : R.string.open, button -> {
678679
try {
679680
startActivity(intent);
680681
notificationManager.cancel(notificationId);

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
<!-- Action Buttons -->
1818
<string name="open">open</string>
19+
<string name="install">install</string>
1920
<string name="reset">reset</string>
2021
<string name="copy">copy</string>
2122

0 commit comments

Comments
 (0)