为什么getPackageArchiveInfo返回null

时间:2016-04-12 07:11:00

标签: java android

我想使用getPackageArchiveInfo获取其他apk的资源,但我得到null,我不知道哪里出错。这是我的代码。

   public void loadSkinAsync(String dexPath, final loadSkinCallBack callback) {
        new AsyncTask<String, Void, Resources>() {

            protected void onPreExecute() {
                if (callback != null) {
                    callback.startloadSkin();
                }
            }

            @Override
            protected Resources doInBackground(String... params) {
                try {
                    if (params.length == 1) {

                        String dexPath_tmp = params[0];
                        File file = new File(dexPath_tmp);
                        PackageManager mPm = mContext.getPackageManager();
                        PackageInfo mInfo = mPm.getPackageArchiveInfo(dexPath_tmp, PackageManager.GET_ACTIVITIES);

                        mPackageName = mInfo.packageName;

                        AssetManager assetManager = AssetManager.class.newInstance();
                        Method addAssetPath = assetManager.getClass().getMethod("addAssetPath", String.class);
                        addAssetPath.invoke(assetManager, dexPath_tmp);

                        Resources superRes = mContext.getResources();
                        Resources skinResource = new Resources(assetManager, superRes.getDisplayMetrics(), superRes.getConfiguration());
                        return skinResource;
                    }
                    return null;
                } catch (Exception e) {
                    e.printStackTrace();
                    return null;
                }

            }

            protected void onPostExecute(Resources result) {
                mResources = result;

                if (callback != null) {
                    if (mResources != null) {
                        callback.loadSkinSuccess();
                    } else {
                        callback.loadSkinFail();
                    }
                }
            }

        }.execute(dexPath);
    }

首先我得到PackageManager,然后用它来获取PackageInfo,但是PackageInfo为null。

0 个答案:

没有答案