06_intent and intentfilter

Source: Internet
Author: User

Intent is a medium for message transmission between components in the same or different applications. It is an abstract description of the action to be executed and is generally used as a parameter.

 

Intent describes the basic components to be started;

Intentfilter filters components.

 

The following code uses intent to enable the activity, open an image, call 10086, and open a webpage.

 

Package COM. example. intentdemo; import Java. io. file; import android. support. v7.app. actionbaractivity; import android. view. view; import android. content. intent; import android.net. uri; import android. OS. bundle; public class mainactivity extends actionbaractivity {@ override protected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); findviewbyid (R. id. btnstartaty1 ). setonclicklistener (new view. onclicklistener () {@ override public void onclick (view v) {// explicitly intent // intent I = new intent (); // I. setcomponent (New componentname ("com. example. intentdemo "," com. example. intentdemo. aty1 "); // start with an action, started by the operating system // implicit intent I = new intent (" com. example. intentdemo. intent. action. ayt1 "); startactivity (I) ;}}); findviewbyid (R. id. btnopenimage ). setonclicklistener (new view. onclicklistener () {@ override public void onclick (view v) {file F = new file ("/storage/emulated/0/pictures/screenshots/Screenshot_2014-08-30-08-08-10.png "); intent I = new intent (intent. action_view); I. setdataandtype (URI. fromfile (F), "image/*"); startactivity (I) ;}}); findviewbyid (R. id. btndel10086 ). setonclicklistener (new view. onclicklistener () {@ override public void onclick (view v) {intent I = new intent (intent. action_view); I. setdata (URI. parse ("Tel: 10086"); startactivity (I) ;}}); findviewbyid (R. id. btnopenbaidu ). setonclicklistener (new view. onclicklistener () {@ override public void onclick (view v) {intent I = new intent (intent. action_view, Uri. parse ("http://www.baidu.com"); startactivity (I );}});}}

Manifest file:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.intentdemo"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="19" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name="com.example.intentdemo.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity><activity android:name="Aty1">            <intent-filter>                <category android:name="android.intent.category.DEFAULT" /><action android:name="com.example.intentdemo.intent.action.Ayt1" />                            </intent-filter>        </activity>                <activity android:name="ImageViewer">                        <intent-filter >                                <action android:name="android.intent.action.view"/>                <category android:name="android.intent.category.DEFAULT"/>                <data android:mimeType="image/*" android:scheme="file"/>                            </intent-filter>                    </activity>    </application></manifest>

 

06_intent and intentfilter

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.