在targetSdkVersion 28(非市场)中更新APK问题

时间:2018-12-05 04:41:38

标签: android updates auto-update target-sdk targetsdkversion

APK一直更新良好,直到targetSdkVersion 24 ,但是在 28(最新)中存在问题。我的应用程序不在PlayStore上。如果版本号更改,则需要更新。问题是当版本号在28个targetSdkVersion中递增时,App未更新 这是我的代码:

try {
        File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath() + "/Download/"+appName);
        file.setReadable(true, false);
        Uri fileUri = Uri.fromFile(file);
        if (Build.VERSION.SDK_INT >= 24) {
            fileUri = FileProvider.getUriForFile(UpdateActivity.this, getPackageName()+ ".provider",
                    file);
        }
        Intent intent = new Intent(Intent.ACTION_INSTALL_PACKAGE, fileUri);
        intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
        intent.setDataAndType(fileUri, "application/vnd.android" + ".package-archive");
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        startActivity(intent);
        finish();
    } catch (Exception e) {
        Toast.makeText(this, "Something went Wrong.Remove old XYZ app & install it from Download folder", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }

在清单中

<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.updateapp.provider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths" />
</provider>

提供者路径:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>
</paths>

我需要它来更新targetSdkVersion 28中的APK。感谢您的帮助

0 个答案:

没有答案