美文网首页
知识体系八:解析 apk 文件

知识体系八:解析 apk 文件

作者: WangRain1 | 来源:发表于2020-05-07 17:58 被阅读0次

    手动解析apk文件:

        String path = Environment.getExternalStorageDirectory() +"/Music/ambience.apk";
        File file =new File(path);
        PackageManager manager = getPackageManager();
        PackageInfo info = manager.getPackageArchiveInfo(path,PackageManager.GET_ACTIVITIES);
        Log.e("=====packageName=======" + info.applicationInfo.icon,"=========" + info.applicationInfo.labelRes);
        AssetManager assets =null;
        try {
            assets = AssetManager.class.newInstance();
            Method method = AssetManager.class.getMethod("addAssetPath",String.class);
            method.invoke(assets,path);
        }catch (Exception e) {
            Log.e("==packageName===","=======1====" + e);
        }
       Resources resources =new Resources(assets, getResources().getDisplayMetrics(), getResources().getConfiguration());           textView.setImageDrawable(resources.getDrawable(info.applicationInfo.icon));
        Log.e("==packageName===","=======1====" + resources.getString(info.applicationInfo.labelRes));
        String clas =null;
        for (ActivityInfo ac : info.activities){
         if ("LauncherActivity".equals(resources.getString(ac.labelRes))){
             clas = ac.name;
             break;
            }
    }
    Log.e("==activity===" + clas,"==LauncherActivity==");
        Intent intent =new Intent();
        intent.setComponent(new ComponentName(info.packageName,clas));
        startActivity(intent);
    }

    相关文章

      网友评论

          本文标题:知识体系八:解析 apk 文件

          本文链接:https://www.haomeiwen.com/subject/tcmoghtx.html