How to launch another app in Android app

Source: Internet
Author: User

One app in Android launches another application generally there are 2 different cases,

The package name of the application being launched is known and unknown in two cases:

1 The package name of the app being launched is known:

   /** launches another applied code, where the app's package named PackageName, the        application's entry is packagename.mainactivity,      None of the 2 application Androidmanifest.xml files for this method need to be modified     **/       Intent Intent = new Intent ();       Intent.setcomponent (New ComponentName ("PackageName", "packagename.mainactivity"));       Intent.setaction (Intent.action_view);       StartActivity (Intent);    

2 The package name of the application being launched is unknown:

This situation is not known about the package name of the app, but the final launch of the app is through the package name. So a way to get the package name of the app in the phone.
The pre-installed and non-system applications can be judged by the method below, returning a list of package names:

Public list<packageinfo> Getallapps () {             list<packageinfo> apps = new arraylist<packageinfo> ();             Packagemanager Packagemanager = This.getpackagemanager ();             Get all apps in your phone             list<packageinfo> paklist = packagemanager.getinstalledpackages (0);                 for (int i = 0; i < paklist.size (); i++) {                 PackageInfo Pak = (packageinfo) paklist.get (i);                 Determine if a non-system preinstalled application  (greater than 0 is pre-installed for the system, less than or equal to 0 for non-system applications)               if ((Pak.applicationInfo.flags & Pak.applicationInfo.FLAG_ SYSTEM) <= 0) {                     apps.add (Pak);                 }             }             return apps;     }   

Since this is a list collection of package names: We're still not sure which app we're going to launch, okay, we can get the app name further.

Public string[] Launchapp () {           Packagemanager Packagemanager = This.getpackagemanager ();           list<packageinfo> packages = Getallapps ();         Str3=new string[packages.size ()];        PackageInfo pa = null;           for (int i=0;i<packages.size (); i++) {               pa = packages.get (i);               Get the app name. The STR3 here is an array of my definition that hosts the application name.            Str3[i] = Packagemanager.getapplicationlabel (pa.applicationinfo). toString ();             }     return STR3;    }   

Finally, you can judge each item based on the number of app names and string[] groups that we want to start. If true, the application is launched and, if Fause, the next judgment is made.

How to launch another app in Android app

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.