fix: optimize querying download uri (#232)
This commit is contained in:
parent
64df08f91c
commit
7504bb9081
1 changed files with 3 additions and 21 deletions
|
@ -161,21 +161,8 @@ object AppUpdater {
|
||||||
DownloadManager.EXTRA_DOWNLOAD_ID, id
|
DownloadManager.EXTRA_DOWNLOAD_ID, id
|
||||||
) ?: id
|
) ?: id
|
||||||
|
|
||||||
val query = DownloadManager.Query()
|
downloadManager.getUriForDownloadedFile(downloadId)?.let {
|
||||||
query.setFilterById(downloadId)
|
openApk(this@downloadUpdate, it)
|
||||||
val c = downloadManager.query(query)
|
|
||||||
|
|
||||||
if (c.moveToFirst()) {
|
|
||||||
val columnIndex = c.getColumnIndex(DownloadManager.COLUMN_STATUS)
|
|
||||||
if (DownloadManager.STATUS_SUCCESSFUL == c
|
|
||||||
.getInt(columnIndex)
|
|
||||||
) {
|
|
||||||
c.getColumnIndex(DownloadManager.COLUMN_MEDIAPROVIDER_URI)
|
|
||||||
val uri = Uri.parse(
|
|
||||||
c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))
|
|
||||||
)
|
|
||||||
openApk(this@downloadUpdate, uri)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logError(e)
|
logError(e)
|
||||||
|
@ -190,16 +177,11 @@ object AppUpdater {
|
||||||
private fun openApk(context: Context, uri: Uri) {
|
private fun openApk(context: Context, uri: Uri) {
|
||||||
try {
|
try {
|
||||||
uri.path?.let {
|
uri.path?.let {
|
||||||
val contentUri = FileProvider.getUriForFile(
|
|
||||||
context,
|
|
||||||
BuildConfig.APPLICATION_ID + ".provider",
|
|
||||||
File(it)
|
|
||||||
)
|
|
||||||
val installIntent = Intent(Intent.ACTION_VIEW).apply {
|
val installIntent = Intent(Intent.ACTION_VIEW).apply {
|
||||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||||
putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
|
putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true)
|
||||||
data = contentUri
|
data = uri
|
||||||
}
|
}
|
||||||
context.startActivity(installIntent)
|
context.startActivity(installIntent)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue