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?