以编程方式安装apk时解析软件包错误

时间:2020-06-10 09:43:29

标签: android auto-update android-install-apk parse-error

我正在安装apk,我可以从服务器成功下载apk,但是在安装时 this is the error i am getting.

这些是关于我的代码的一些信息。

AndroidManifest.xml

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES"/>

        <provider
            android:name=".GenericFileProvider"
            android:authorities="com.example.web_view.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>


**filepath.xml**

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="."/>   
</paths>

Splash.java

                                                    BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
                                                        @Override
                                                        public void onReceive(Context context, Intent intent) {


                                                            File file_dir=new File("/storage/emulated/0/Download/",URLUtil.guessFileName(url, contentDisposition, mimetype));
                                                            Uri path = FileProvider.getUriForFile(context,context.getApplicationContext().getPackageName()+".provider",file_dir);
                                                            if(file_dir.setReadable(true,false))
                                                            {
                                                                Toast.makeText(context, "made readble", Toast.LENGTH_LONG).show();
                                                            }
                                                            Intent pdfOpenintent = new Intent(Intent.ACTION_VIEW);
                                                            pdfOpenintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

                                                            pdfOpenintent.setDataAndType(path, downloadManager.getMimeTypeForDownloadedFile(download));
                                                            pdfOpenintent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                                                            pdfOpenintent.setFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                                                            context.grantUriPermission(BuildConfig.APPLICATION_ID,path,Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                                                            context.startActivity(pdfOpenintent);
                                                            context.unregisterReceiver(this);
                                                            finish();
                                                        }
                                                    };
                                                    registerReceiver(broadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));

logcat

java.lang.SecurityException: Permission Denial: reading com.example.web_view.GenericFileProvider uri content://com.example.web_view.provider/external_files/Download/google.apk from pid=3032, uid=10028 requires the provider be exported, or grantUriPermission()
        at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:642)
        at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:503)
        at android.content.ContentProvider$Transport.enforceFilePermission(ContentProvider.java:494)
        at android.content.ContentProvider$Transport.openTypedAssetFile(ContentProvider.java:422)
        at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:302)
        at android.os.Binder.execTransact(Binder.java:731)
2020-06-10 14:28:09.919 2900-2900/com.example.web_view E/chromium: [ERROR:aw_browser_terminator.cc(125)] Renderer process (2950) crash detected (code -1).

我在Google上进行了搜索,但没有找到可以纠正此错误的任何相关答案。

0 个答案:

没有答案