From 22346fbf819d937421756b389ac5dbabacd91a60 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Tue, 7 Jan 2020 17:36:41 +0100 Subject: [PATCH] Fix issue with new Android to install apk --- .../ContributionVersionActivity.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java b/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java index e875cbdf42..759b740909 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ContributionVersionActivity.java @@ -4,7 +4,9 @@ import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; +import android.os.Build; import android.os.Bundle; +import android.support.v4.content.FileProvider; import android.support.v7.app.AlertDialog; import android.view.LayoutInflater; import android.view.View; @@ -16,6 +18,7 @@ import android.widget.TextView; import android.widget.Toast; import net.osmand.AndroidUtils; import net.osmand.osm.io.NetworkUtils; +import net.osmand.plus.BuildConfig; import net.osmand.plus.R; import net.osmand.plus.Version; @@ -109,11 +112,18 @@ public class ContributionVersionActivity extends OsmandListActivity { } } else if(operationId == INSTALL_BUILD){ if(currentSelectedBuild != null){ - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - intent.setDataAndType(Uri.fromFile(pathToDownload), "application/vnd.android.package-archive"); - startActivityForResult(intent, ACTIVITY_TO_INSTALL); - updateInstalledApp(false, currentSelectedBuild.date); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + Uri apkUri = FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", pathToDownload); + Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE); + intent.setData(apkUri); + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + } else { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setDataAndType(Uri.fromFile(pathToDownload), "application/vnd.android.package-archive"); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + startActivityForResult(intent, ACTIVITY_TO_INSTALL); + } + updateInstalledApp(false, currentSelectedBuild.date); } } }