How do I activate a third-party application in Android?

Source: Internet
Author: User

How do I start a third-party application interface after I click a key?

/*** < function description > Launch application * *@returnvoid [return type description]*/    Private voidstartupapplication (String pkg) {Packagemanager Packagemanager=Mcontext.getpackagemanager (); PackageInfo PackageInfo=NULL; Try {            //gets the PackageInfo instance of the application that specifies the package namePackageInfo = packagemanager.getpackageinfo (pkg, 0); } Catch(namenotfoundexception e) {//application not found for the specified package nameE.printstacktrace (); //Tip No GPS Test plus appToast.maketext (msptactivity, msptactivity.getstring (R.string.gps_no_test_plus),            Toast.length_short). Show (); return; }        if(PackageInfo! =NULL) {            //Installed AppsIntent resolveintent =NewIntent (Intent.action_main,NULL);            Resolveintent.addcategory (Intent.category_launcher);            Resolveintent.setpackage (Packageinfo.packagename); List<ResolveInfo> apps =packagemanager.queryintentactivities (resolveintent,0); ResolveInfo RI=NULL; Try{ri=Apps.iterator (). Next (); } Catch(Exception e) {e.printstacktrace (); return; }            if(RI! =NULL) {                //Gets the startup activity class name for the applicationString ClassName =Ri.activityInfo.name; //Activate the activity for the applicationIntent Intent =NewIntent (Intent.action_main);                Intent.addcategory (Intent.category_launcher); ComponentName componentname=Newcomponentname (pkg, className);                Intent.setcomponent (componentname);            Mcontext.startactivity (Intent); }        }    }

To open an app that specifies a package name, provide the package name:

// Gps Test plus application package name startupapplication ("Com.chartcross.gpstestplus");

The above string: Com.chartcross.gpstestplus is the package name of the GPS Test plus app provided by Google.

Questions:

1. The reality is: you may not be able to start the application after the first time you brush the machine. How do I resolve this issue?

2. Leave the future ...

How do I activate a third-party application in Android?

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.