Launch another app in Android essay--activity

Source: Internet
Author: User

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

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.