App launches other apps

Source: Internet
Author: User

Because the development needs to package an app, so to launch an app, this operation if you know the package name and class name is actually very simple only need to embed the package name (in general, we can decompress or reverse access)

The code is as follows:

Intent Intent = new Intent (intent.action_main);  
Set the package name and class name ComponentName Mcomponentname = new ComponentName ("Com.kukum.mynews", "com.kukum.android.SplashActivity"); Intent.setcomponent (Mcomponentname); StartActivity (Intent);

But if you do not know the class name, you need to get the package information based on the package name and then get the startup class to jump code as follows

Create a class with the same package name Category_launcher intentintent resolveintent = new Intent (intent.action_main, NULL); Resolveintent.addcategory (Intent.category_launcher); Resolveintent.setpackage ("com.kukum.mynews");// Traverse  list<resolveinfo> resolveinfolist = GetPackageManager () through the Queryintentactivities method of the Getpackagemanager () . Queryintentactivities (resolveintent, 0);//Because there is a category and action associated so the startup class has only one if there is a startup class Resolveinfo Resolveinfo = Resolveinfolist.iterator (). Next (); if (resolveinfo! = null) {String className = resolveinfo.activityinfo.name;intent Intent = new Intent (Intent.action_main); intent.addcategory (Intent.category_launcher); ComponentName mcomponentname = new ComponentName ("Com.kukum.mynews", ClassName); Intent.setcomponent (Mcomponentname) ; StartActivity (intent);}

Get

App launches other apps

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.