Can We Install an APK From a ContentProvider?

后端 未结 4 1065
忘了有多久
忘了有多久 2020-12-08 03:57

I am working on a library to allow apps to self-update, for those that are being distributed outside of the Android Market.

My original plan was to include code that

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 04:28

    I agree with Jules analysis, and I would add concrete precisions :

    In PackageInstallerActivity, which is called by ACTION_VIEW on an apk, there is this in the onCreate() method:

    315 String apkPath = mPackageURI.getPath();
    316 File apkFile = new File(apkPath);
    

    And before that, this method from PackageUtil is called:

    73 public static  PackageParser.Package getPackageInfo(Uri packageURI) {
    74     final String archiveFilePath = packageURI.getPath();
    75     PackageParser packageParser = new PackageParser(archiveFilePath);
    76     File sourceFile = new File(archiveFilePath);
    77     DisplayMetrics metrics = new DisplayMetrics();
    78     metrics.setToDefaults();
    79     return packageParser.parsePackage(sourceFile, archiveFilePath, metrics, 0);
    80 }
    

    All this tends to confirm that the PackageManager do expects only File Uris.

    The log you have, Skipping dir: is found in packageParser.parsePackage, which tests whether the path given in the Uri is a file or not.

提交回复
热议问题