Android-Launches another installed application or system program in one application (provided you know the main activity and package name of the application)

Source: Internet
Author: User

Component name, the first parameter is the package name of the application, and the latter is the main activity of the application
componentname com = new ComponentName ("Com.antroid.Test", "com.antroid.Test.TestActivity");

Intent Intent = new Intent ();


Set up Parts
Intent.setcomponent (COM);

StartActivity (Intent);


We can also use the following code to start the system's calendar program:
[JavaScript]
Intent intent=new Intent ();
Intent.setcomponent (New ComponentName ("Com.android.calendar", "com.android.calendar.LaunchActivity"));
StartActivity (Intent);

Intent intent=new Intent ();
Intent.setcomponent (New ComponentName ("Com.android.calendar", "com.android.calendar.LaunchActivity"));
StartActivity (Intent)


third :
turn from:/http www.eoeandroid.com/forum.php?mod=viewthread&tid=69600


The system provides a lot of activity that can be called directly, Can be called by the specified intent, such as open search:

    1. Intent Intent = new Intent (intent.action_web_search);
    2. Intent.putextra (Searchmanager.query, "searchstring")
    3. StartActivity (Intent);
Copy Code

Intent.action_web_search is a string that is the identity of the "search" activity, and extra is some data passed to the activity. After sending out this intent, the system knows what activity to invoke based on the ACTION string intent.action_web_search, and if there is a duplicate name, a selection dialog box pops up. Then open the activity and implement what you want to do.

So, how do we come to realize it ourselves.

First, write an activity, in the androidmanifest.xml inside the intent-filter, give this activity name:

    1. <intent-filter>
    2. <action android:name= "Chroya.foo"/>
    3. <category android:name= "Android.intent.category.DEFAULT"/>
    4. </intent-filter>
Copy Code


and then install. Once the installation is complete, you will find that the program is not found in the system. Don't worry, it's actually installed in the phone, but because he's not main, the system doesn't think of him as a application entry program.

And to open this activity, only the person who knows its name can. Use the same as the intent of the system. Its name is defined as "Chroya.foo", so it can be called with this string:

    1. Intent Intent = new Intent ("Chroya.foo");
    2. StartActivity (Intent);
Copy Code

The intent of the system that was just lifted shows that its activity uses getintent (). Getbundleextra (Searchmanager.query) to receive the passed in search string parameter. And this searchmanager.query is the key word. If you want to do this yourself, you just need to define the keyword and then take it from the Bundleextra.

Android-Launches another installed application or system program in one application (provided you know the main activity and package name of the application)

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.