mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Updater fixes
This commit is contained in:
parent
763589fa0d
commit
207f8656dd
2 changed files with 36 additions and 10 deletions
|
|
@ -41,6 +41,16 @@
|
||||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<provider
|
||||||
|
android:name="androidx.core.content.FileProvider"
|
||||||
|
android:authorities="${applicationId}.provider"
|
||||||
|
android:exported="false"
|
||||||
|
android:grantUriPermissions="true">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||||
|
android:resource="@xml/provider_paths" />
|
||||||
|
</provider>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import kotlinx.serialization.json.jsonObject
|
||||||
import kotlinx.serialization.json.jsonPrimitive
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
|
import okhttp3.Response
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
@ -212,8 +213,18 @@ class UpdateChecker
|
||||||
intent.data = uri
|
intent.data = uri
|
||||||
context.startActivity(intent)
|
context.startActivity(intent)
|
||||||
} else {
|
} else {
|
||||||
Timber.e("Resolver URI is null")
|
Timber.e("Resolver URI is null, trying fallback")
|
||||||
// TODO show error Toast
|
// showToast(context, "Unable to download the apk")
|
||||||
|
val targetFile = fallbackDownload(it)
|
||||||
|
val intent = Intent(Intent.ACTION_INSTALL_PACKAGE)
|
||||||
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
intent.data =
|
||||||
|
FileProvider.getUriForFile(
|
||||||
|
activity,
|
||||||
|
activity.packageName + ".provider",
|
||||||
|
targetFile,
|
||||||
|
)
|
||||||
|
activity.startActivity(intent)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ContextCompat.checkSelfPermission(
|
if (ContextCompat.checkSelfPermission(
|
||||||
|
|
@ -234,13 +245,7 @@ class UpdateChecker
|
||||||
PERMISSION_REQUEST_CODE,
|
PERMISSION_REQUEST_CODE,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
val downloadDir =
|
val targetFile = fallbackDownload(it)
|
||||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
|
||||||
downloadDir.mkdirs()
|
|
||||||
val targetFile = File(downloadDir, ASSET_NAME)
|
|
||||||
targetFile.outputStream().use { output ->
|
|
||||||
it.body!!.byteStream().copyTo(output)
|
|
||||||
}
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
val intent = Intent(Intent.ACTION_INSTALL_PACKAGE)
|
val intent = Intent(Intent.ACTION_INSTALL_PACKAGE)
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
|
|
@ -261,12 +266,23 @@ class UpdateChecker
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Timber.v("Request failed for ${release.downloadUrl}: ${it.code}")
|
Timber.v("Request failed for ${release.downloadUrl}: ${it.code}")
|
||||||
// TODO show error toast
|
showToast(context, "Error downloading the apk: ${it.code}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun fallbackDownload(response: Response): File {
|
||||||
|
val downloadDir =
|
||||||
|
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
||||||
|
downloadDir.mkdirs()
|
||||||
|
val targetFile = File(downloadDir, ASSET_NAME)
|
||||||
|
targetFile.outputStream().use { output ->
|
||||||
|
response.body!!.byteStream().copyTo(output)
|
||||||
|
}
|
||||||
|
return targetFile
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete previously downloaded APKs
|
* Delete previously downloaded APKs
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue