При синтаксическом анализе пакета возникла проблема.
Код: Выделить всё
private void startDownload() {
// Start downloading the APK
String destination = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString();
String fileName = "newversion.apk";
File dir = new File(destination);
Fuel.INSTANCE.download("https://xxxxxxx/apps/PV-latest.apk", Method.GET, null)
.fileDestination((request, response) -> {
// Return the file where the APK should be saved
return new File(dir, fileName); // Save the file in the specified directory
})
.response((request, response, result) -> {
runOnUiThread(() -> {
Toast.makeText(this, "Download complete", Toast.LENGTH_SHORT).show();
// Start the installation process
installAPK(new File(dir, fileName));
});
return null;
});
}
private void installAPK(File file) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
// For Android Nougat and above, use FileProvider
intent.setDataAndType(FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".provider", file), "application/vnd.android.package-archive");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent);
}
Разрешения из AndroidManifest.xml:
Код: Выделить всё
Код: Выделить всё
android {
namespace = "com.example.xxxx"
compileSdk = 34
defaultConfig {
applicationId = "com.example.xxxx"
minSdk = 27
targetSdk = 34
versionCode = 1
versionName = "1.1.1"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("debug")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
buildFeatures {
viewBinding = true
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... oid-10-why
Мобильная версия