Parse some attributes of the AndroidManifest. xml file and obtain the specified configuration value in the code.
1) manifest --> package
The package name of an application, which is the unique identifier of each application. Each application must specify this value. The system uses this value to differentiate and find different applications.
Code for obtaining this attribute:
/*** Get the application package name (apk package name, not the registration of the class) * @ param conext Activity in the program, application Instances can be */public static String getAppPackageName (Context context) {if (context! = Null) {return context. getPackageName ();} return "";}
2) manifest --> versionCode
The version number of the current app, which is used for app upgrade. An apk with a small versionCode can be upgraded to an apk with a large versionCode. However, an apk with a small versionCode cannot overwrite a large version of versionCode and must be uninstalled first.
Code for obtaining this attribute:
/*** Get the program version * @ param conext Activity in the program. The Application instance can * @ return-1 get failed */public static int getAppVersionCode (Context context Context) {try {PackageManager pm = context. getPackageManager (); PackageInfo pi = pm. getPackageInfo (context. getPackageName (), 0); return pi. versionCode;} catch (Exception e) {e. printStackTrace (); GoogleAnalyticsTool. getInstance (). sendException (1, e);} return-1 ;}
3) manifest --> versionName
Current app version name
Code for obtaining this attribute:
/*** Get the program version name * @ param conext Activity in the program. The Application instance can all be */public static String getAppVersionName (Context context) {String versionName = ""; try {PackageManager pm = context. getPackageManager (); PackageInfo pi = pm. getPackageInfo (context. getPackageName (), 0); versionName = pi. versionName;} catch (Exception e) {e. printStackTrace (); GoogleAnalyticsTool. getInstance (). sendException (1, e);} return versionName ;}
4) manifest --> application --> debuggable
Whether to enable the debug mode. This attribute can be left unspecified.
True: it is in debug mode. You can debug the application using a tool and break the breakpoint.
False: Non-debug mode. You cannot debug an application using a debugging tool. The breakpoint is invalid.
Code for obtaining this attribute:
/*** Get whether it is the Activity in the debug mode * @ param conext program. The Application instance can all be */public static boolean isDebugMode (Context context) {if (context = null) {Log. e ("Utils: isDebugMode", "context is null"); return false;} ApplicationInfo = context. getApplicationInfo (); return (0! = (Info. flags) & ApplicationInfo. FLAG_DEBUGGABLE ));}
For more information, see jiese1990.