the premise of using Android to hide the API: we need to get the Android system source code compiled output of a file
Out\\target\\common\\obj\\java_libraries\\framework_intermediates\\Classes.jar
This package contains all the system APIs, hidden, public
Adding a Jar method
Right-click function menu->properties->java Build Path
Libraries tab
There should be a list, if you have not added, there should be only one item, is the system comes with the Android SDK, selected, the right hand side has a delete, first remove the system added SDK.
Click Add Library--User Library
Select the User library button and create a new user library to import the files from the file Classes.jar and the system itself, adjust the order, and move the Classes.jar to the front
Once this has been added, you can use the system-hidden API
Using the Hide API, there is a premise:
Many APIs involve system permissions issues, such as the background installation file API Packagemanager.installpackage requires the installation program permissions, and this installer installation program permissions are not random, only the ROM signed by the authentication can use this permission . Although it is possible to add this permission in the configuration file, but the tragedy is that you still can't have this permission , at this point, Google did really absolutely.
OK, although we can not install, but with the API to see the apk always be OK?
Google does not disclose this API, but the above method, we can use the//APK package file path
String Apkpath =
\ "/sdcard/qq.apk\";
//This is a package interpreter that is hidden
constructor parameters only one, the path of the APK file
Packageparser Packageparser =
New Packageparser (Apkpath);
This is related to the display, which involves some pixel display and so on, we use the default case
Displaymetrics metrics =
New Displaymetrics ();
Metrics.settodefaults ();
Here is the parse, four parameters,
source file,
Destination file path
Display, Displaymetrics Metrics
Flags
packageparser.package mpkginfo = packageparser.parsepackage (new File (Apkpath),
Apkpath, metrics, 0);
Application information Package, this public, but some functions, variables are not public
applicationinfo info = mpkginfo.applicationinfo;
Resources are used to obtain resources, and the resource obtained here is outside of this program.
Resources pRes = getresources ();
Assetmanager assmgr =
New Assetmanager ();
Assmgr.addassEtpath (Apkpath); //This method is hidden, not to call the hidden API, to be reflected in order to invoke
Resources res =
New Resources (Assmgr, Pres.getdisplaymetrics (), pres.getconfiguration ());
Charsequence label =
Null
if (info.labelres! =
0) {
try {
label = Res.gettext (info.labelres);
} catch (Resources.notfoundexception e) {
}
}
if (label = =
NULL) {
Label = (Info.nonlocalizedlabel! =
NULL)?
Info.nonLocalizedLabel:info.packageName;
}
Here is the icon to read an APK program
if (Info.icon! =
0) {
drawable icon = res.getdrawable (info.icon);
ImageView image = (ImageView) Findviewbyid (r.id.iv_test);
Image.setvisibility (view.visible);
Image.setimagedrawable (icon);
}
}
=============================================
PS: Avoid the hassle of reflection calls by using the Hide API.
How to use the Hide API in Android engineering