The principle of implementation: relatively simple, mainly intent specific use, the code is as follows:
1 /**2 * 3 * @ClassName: mainactivity4 * @Description: Jump from one app to another5 * @authorGuoyizhe6 * @email [email protected]7 * @date 2015-6-9 pm 3:49:078 *9 */Ten Public classMainactivityextendsActivity { One A PrivateIntent Intent =NULL; - @Override - protected voidonCreate (Bundle savedinstancestate) { the Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); - //know the package name, class name to jump to app - //componentname comp = new ComponentName ("Com.gyz.mytextswitchertest", "com.gyz.mytextswitchertest.MainActivity" ); + //final Intent Intent = new Intent (); - //intent.setcomponent (comp); + //intent.setaction ("Android.intent.action.VIEW"); A //do not know the class name atPackagemanager pm =Getpackagemanager (); -PackageInfo pi =NULL; - Try { -PI = Pm.getpackageinfo ("Com.gyz.mytextswitchertest", 0); -}Catch(namenotfoundexception e) { - e.printstacktrace (); in } - toIntent resolveintent =NewIntent (Intent.action_main,NULL); + resolveintent.addcategory (intent.category_launcher); - resolveintent.setpackage (pi.packagename); the * //Find all activity matching intent, this method can be called before intent jump to detect whether there are eligible activity $List<resolveinfo> apps = pm.queryintentactivities (resolveintent, 0);Panax NotoginsengResolveInfo ri =Apps.iterator (). Next (); - if(RI! =NULL ) { theString ClassName =Ri.activityInfo.name; + AIntent =NewIntent (intent.action_main); the intent.addcategory (intent.category_launcher); + -ComponentName cn =NewComponentName ("Com.gyz.mytextswitchertest", ClassName); $ $ Intent.setcomponent (CN); - } -Button Button =(Button) Findviewbyid (r.id.btn_jump); theButton.setonclicklistener (NewOnclicklistener () { - Wuyi @Override the Public voidOnClick (View v) { - startactivity (intent); Wu } - }); About } $}
Android app Jump