Principle: See the next Android source code, understand the resolution process, just their own words will be transplanted Android source code, someone resolved successfully, but I feel too troublesome. About the Android parsing process.
Public PackageInfo Getpackagearchiveinfo (String archivefilepath, int flags) { Packageparser packageparser = new Packageparser (Archivefilepath); Displaymetrics metrics = new Displaymetrics (); Metrics.settodefaults (); Final file SourceFile = new file (Archivefilepath); Packageparser.package pkg = packageparser.parsepackage ( sourcefile, Archivefilepath, metrics, 0); if (pkg = = null) { return null; } if ((Flags & get_signatures)! = 0) { packageparser.collectcertificates (pkg, 0); } Return packageparser.generatepackageinfo (pkg, NULL, flags, 0, 0); }
Here is the source code, first through Packageparser parsing, Then through the packageparser.generatepackageinfo back to PackageInfo, but packageinfo in the intent-filter to remove, do not know why, but since know this piece of code so good to run. That is to get the packageparser.package through reflection and then encapsulate it into intentfilter. Solution: Directly on the code. Because it's all just a reflection and rewriting the code once.
try {//Get parse Class Packageparser and instantiate class Packageparserclass = Class.forName ("Android.content.pm.PackageParser"); Object Packageparser = Packageparserclass.getconstructor (String.class). newinstance (Dexpath); Build parameters Displaymetrics metrics = new Displaymetrics (); Metrics.settodefaults (); File SourceFile = new file (Dexpath); Call Packageparser's Parsepackage parse data method = Packageparserclass.getdeclaredmethod ("Parsepackage", File.class, String.class, Displaymetrics.class, Int.class); Method.setaccessible (TRUE); Object package = Method.invoke (Packageparser, sourcefile, Dexpath, metrics, 0); The reflection results from Field activities = Package.getclass (). Getdeclaredfield ("Activities"); Activities.setaccessible (TRUE); ArrayList filters = (ArrayList) activities.get (package); for (int i = 0; i < filters.size (); i++) {Object activity = filters.get (i); Field Intentsfield = Activity.getclass (). GetField ("intents"); Intentsfield.setaccessible (TRUE); Arraylist<intentfilter> intents = (arraylist<intentfilter>) intentsfield.get (activity); for (int j = 0; J < Intents.size (); j + +) {if (Intents.iterator (). Hasnext ()) {String actionstring = INTENTS.G ET (0). getaction (0); String categorystring = intents.get (0). getcategory (0); System.out.println (actionstring + "" + categorystring); }}}} catch (Exception e) {}
Dexpath is the path to the apk you want to parse. There are action and category in Intentfilter. This realizes to get an activity of the resolveinfo, as for why to type wandering, then the specific look at Android source code bar.
[Android] teaches you how to get resolveinfo for apps that aren't installed