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