Recently in the Write speech interactive program, the voice open application this block encounters how to control the application startup with code. Baidu a bit, there are two options: 1, get the app's package name, 2, get the app's package name, the entry class name.
Before the two scenarios have been tried, found that there is a disadvantage of the scenario two, that is, system-level applications can only get the package name, cannot get to the entry class name, which will cause the program error, of course, you can not get the system-level application package name and the entry class name. For the sake of simple and convenient consideration, chose the scheme one, the nonsense does not say much, on the code.
Programme I,
1. Get Package Name:
1 //Get Packagemanager Object2Packagemanager Packagemanager =Getpackagemanager ();3 //PackageInfo object for all programs that are installed by the system4list<packageinfo> packages = packagemanager.getinstalledpackages (0);5 //creates an array of type string to hold the acquired package name6Arraylist<string> packagelist =NewArraylist<string>();7 8 for(inti = 0; I < packages.size (); i++) {9PackageInfo PackageInfo =Packages.get (i);Ten One //determine if it is a system-level application A if((PackageInfo.applicationInfo.flags & applicationinfo.flag_system) = = 0) { - Packagelist.add (packageinfo.packagename); - } the}
2. Start the application based on the acquired package name:
1 //Get Packagemanager Object2Packagemanager Packagemanager =Getpackagemanager ();3 //get the package name indexed to I4String PackageName =Packagelist.get (i);5 //If the program is not bootable (like a package that comes with the system, there are many without portals) it returns null6Intent Intent =packagemanager.getlaunchintentforpackage (packagename);7 8 if(Intent! =NULL) {9 startactivity (intent);Ten}
Scenario two, has not been carefully studied, but for those main entrance set <intent-filter> application, plan two should be better than plan one, tomorrow to find a time to fill this up
Launch another app in Android essay--activity