(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

Source: Internet
Author: User

(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.