Intent是同一个或不同的应用中的组件之间的消息传递的媒介,是一个将要执行动作的抽象描述,一般来说是作为参数来使用。

  Intent描述要启动的基本组件;

  IntentFilter对组件进行过滤。

  下面的代码通过Intent,具有打开Activity、打开图片、拨打10086和打开网页的功能。

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) { //显式Intent
//Intent i = new Intent();
//i.setComponent(new ComponentName("com.example.intentdemo", "com.example.intentdemo.Aty1")); //通过一个action来启动,由操作系统来启动
//隐式Intent
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文件:

<?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和IntentFilter的更多相关文章

  1. Intent和IntentFilter详解

    Intent用于启动Activity,Service, 以及BroadcastReceiver三种组件, 同时还是组件之间通信的重要媒介. 使用Intent启动组件的优势1, Intent为组件的启动 ...

  2. [转]android笔记--Intent和IntentFilter详解

    Intent用于启动Activity, Service, 以及BroadcastReceiver三种组件, 同时还是组件之间通信的重要媒介. 使用Intent启动组件的优势1, Intent为组件的启 ...

  3. (备忘)android清单文件中<meta-data>标签,以及<intent-filter>下的<data>标签及其他标签

    1.metadata可以写在application下也可以写在activity下,作为全局或activity内共享的数据 以键值对形式保存 <meta-data android:name=&qu ...

  4. android-Intent and IntentFilter

    一.Intent简介 Android使用Intent来封装程序的调用"意图",Activity.Service.BroadcastReceiver三种重要的组件都是依靠Intent ...

  5. android IntentFilter 使用之 data过滤

    1 Intent分为两大类,显式和隐式. 显式事件,就是指通过 component Name 属性,明确指定了目标组件的事件. 比如我们新建一个Intent,指名道姓的说,此事件用于启动名为" ...

  6. Android,配置Activity为启动Activity(AndroidManifest.xml,application,intent-filter,MAIN,LAUNCHER)

    备忘: 将Activity注册为启动Activity. 在AndroidManifest.xml中的<application>元素中加入以下<activity>子元素内容: & ...

  7. [Xamarin] 透過 intent-filter 來接管 http ,製作偽瀏覽器 (转帖)

    使用Android 的朋友一定對這畫面不陌生在開啟網址的時候,或是Youtube連結的時候,因為Android 發現,你手機安裝的App有哪些可以支援這些東西的瀏覽 所以,就可以使用甚麼東西來進行開啟 ...

  8. 关于IntentFilter的几点注意事项:

    http://blog.csdn.net/cnnumen/article/details/8464786 IntentFilter就是用于描述intent的各种属性, 比如action, catego ...

  9. Intent官方教程(5)在manifest中给组件添加<Intent-filter>

    Receiving an Implicit Intent To advertise which implicit intents your app can receive, declare one o ...

随机推荐

  1. Python之list函数

  2. Android Studio导入github项目源码步骤

    1.从github上将源码下载下来 2.打开AS,新建一个新项目(我选择了EmptyActivity) 3.先不要在AS 中打开源码,来整理源码 在源码的目录下面,将project下的build.gr ...

  3. 分布式文档存储数据库之MongoDB访问控制

    上一篇博客主要聊了下mongodb的分片机制以及分片集群的搭建,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13958295.html:今天我们来了解下mon ...

  4. 关于java和JS中的lastIndexOf方法的误解。

    今天看JS的数组的lastIndexOf()方法,看书上的例子,怎么看都觉得不对劲.后来详细读了几遍解释,用java也测试了下,才发现,之前的理解完全是错误的. 上例子: String nums=&q ...

  5. C++的四种强制转型形式:

    C++同时提供了四种新的强制转型形式(通常称为新风格的或C++风格的强制转型): const_cast(expression)dynamic_cast(expression)reinterpret_c ...

  6. 三:登录功能实现,servlet

    1)servlet 2)request 请求对象 3)response响应对象 4)转发 5)重定向 1.servlet就是用来处理客户端的请求的 1.1去官网下载 1.2 在STS上添加该包ctrl ...

  7. SQL Server数据库Union和Union All查询出数据的区别?

    好久没有更新博客了,可能是最近比较忙,总是忽略了一些事情,今天查了做了一些数据分析的数据,突然感觉对Union和Union all有些不太理解了,可能是自己老了吧,就翻了一些资料,进行回忆和学习,趁着 ...

  8. Dubbo 服务引入-Version2.7.5

    1.服务引用原理 Dubbo 服务引用的时机有两个,第一个是在 Spring 容器调用 ReferenceBean 的 afterPropertiesSet 方法时引用服务,第二个是在 Referen ...

  9. 攻防世界-PHP文件包含

    <?php show_source(__FILE__); echo $_GET['hello']; $page=$_GET['page']; while (strstr($page, " ...

  10. SMBv3远程代码执行漏洞复现(CVE-2020-0796)

    漏洞基本信息 服务器消息块(SMB),是一个网络通信协议,用于提供共享访问到文件,打印机和串行端口的节点之间的网络上.它还提供了经过身份验证的进程间通信机制.SMB的大多数用法涉及运行Microsof ...