Android app Jump

Source: Internet
Author: User

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

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.