1

I want to update the APK programmaticaly but when i see the adb logcat i get the errors:

ActivityManager: Permission Denial: opening provider com.app.termappandroid.Utils.GenericFileProvider from ProcessRecord{5ceeb48 5072:com.google.android.packageinstaller/u0a13} (pid=5072, uid=10013) that is not exported from UID 10088

InstallStaging: Error staging apk from content URI InstallStaging: java.lang.SecurityException: Permission Denial: opening provider com.app.termappandroid.Utils.GenericFileProvider from ProcessRecord{5ceeb48 5072:com.google.android.packageinstaller/u0a13} (pid=5072, uid=10013) that is not exported from UID 10088

Below you see the code:

 @Override
    protected String doInBackground(String... strings) {
        try{
        FTPClient ftpClient = new FTPClient();
        ftpClient.connect("10.0.2.2");
        ftpClient.login("user01", "1234");
        ftpClient.enterLocalPassiveMode();
        String remoteFile1 = "/app-release.apk";
        String downPath = context.getCacheDir().getAbsolutePath();
        File myapk = new File(downPath + "/app-release.apk");
        System.out.println(myapk.getName());
        OutputStream outputStream1 = new BufferedOutputStream(new FileOutputStream(myapk));
        boolean success = ftpClient.retrieveFile(remoteFile1, outputStream1);
        outputStream1.close();
        myapk.setReadable(true, false);

        if (!success) {
            ftpClient.logout();
            ftpClient.disconnect();
            return null;

        } else {

            Intent intent;
            boolean isDebuggable = (0 != (context.getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
            Uri apkUri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".provider", myapk);
            myapk.equals(context.getApplicationContext().getPackageCodePath());
            intent = new Intent(Intent.ACTION_VIEW);
                List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
                for (ResolveInfo resolveInfo : resInfoList) {
                    String packageName = resolveInfo.activityInfo.packageName;
                    context.grantUriPermission(packageName, apkUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
            intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(intent);
        }

        } catch (IOException e) {
            Log.e("UpdateAPP", "Update error! " + e.getMessage());
        }

        return null;
    }

this is mine provider_paths :

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

And this is mine Android manifest :

<provider
        android:name="com.app.termappandroid.Utils.GenericFileProvider"
        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>
David Wasser
  • 93,459
  • 16
  • 209
  • 274

0 Answers0