(1), get the application package name code
/*** Get the version number of the current application * *@return */ PrivateString getversion () {Try{Packagemanager Manager= Getpackagemanager ();//Get package Management ServicePackageInfo Clientinfo =Manager. Getpackageinfo (Getpackagename (),0);//get information about a package returnClientinfo.versionname; } Catch(Exception e) {//TODO auto-generated Catch blockE.printstacktrace (); return"Version number Unknown"; } }
(2), install APK
/** * Install apk * @param file */ privatevoid Install (file file) { new Intent (); Intent.setaction (Intent.action_view); Intent.setdataandtype (uri.fromfile (file), "application/vnd.android.package-archive"); Finish (); StartActivity (intent); }
(3), how to get the activity at the top of the current stack.
The total steps are:
1. Get the activity manager of the current operating environment (context);
2. Get the current task stack information through the Activity manager;
3. Get the name of the activity at the top of the stack from the task stack.
String Get Topactivity (Activity context) { = (Activitymanager) Context.getsystemservice (activity_service); List<RunningTaskInfo> Runningtaskinfos = manager.getrunningtasks (1); if NULL ) return (runningtaskinfos.get (0). topactivity). toString (); Else return NULL ; } Finally, don't forget to add permissions in Androidmanifest.xml:<uses-permission android:name = "Android.permission.GET_TASKS"/>
4, Android How to achieve click on a button to enter the specified page
Uri uri = uri.parse ("http://www.baidu.com"new Intent (Intent.action_view, URI); StartActivity ( Intent);
(31) Tool method: Get application Package name/install apk/How to get the current stack top activity/android how to implement click a button to enter the specified page