一旦为Intent同时指定了Action、Data属性,那么Android将可根据指定的数据类型来启动特定的应用程序,并对指定数据类型执行相应的操作。

下面是几个Action属性、Data属性的组合。

  • ACTION_VIEW  content://com.android.contacts/contacts/1:显示标识为1的联系人的信息。
  • ACTION_EDIT   content://com.android.contacts/contacts/1:编辑标识为1的联系人的信息。
  • ACTION_DIAL   content://com.android.contacts/contacts/1:显示向标识为1的联系人拨号的界面。
  • ACTION_VIEW  tel:123:显示向指定号码123拨号的界面。
  • ACTION_DAL    tel:123:显示向指定号码123拨号的界面。
  • ACTION_VIEW  content://contacts/people/:显示所有联系人列表的信息,通过这种组合可以非常方便地查看系统联系人。

下面的程序示范通过同时为Intent指定Action、Data属性来启动特定程序并操作相应的数据。下面的程序的界面很简单,它只包含两个按钮,其中一个按钮用于浏览指定网页,一个按钮用于编辑指定联系人信息。

package com.example.studyintent;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; public class ActionData extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_action_data);
Button bn=(Button)findViewById(R.id.bn);
//为bn按钮添加一个监听器
bn.setOnClickListener(new OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
//创建Intent
Intent intent=new Intent();
String data="http://www.crazyit.org";
//根据指定字符串解析出Uri对象
Uri uri=Uri.parse(data);
//为Intent设置Action属性
intent.setAction(Intent.ACTION_VIEW);
//设置Data属性
intent.setData(uri);
startActivity(intent);
} }); Button edit=(Button)findViewById(R.id.edit);
//为edit按钮添加一个监听器
edit.setOnClickListener(new OnClickListener(){ @Override
public void onClick(View v) {
// TODO Auto-generated method stub
//创建Intent
Intent intent=new Intent();
//为Intent设置Action属性(动作为:编辑)
intent.setAction(Intent.ACTION_EDIT);
String data="content://com.android.contacts/contacts/1";
//根据指定字符串解析出Uri对象
Uri uri=Uri.parse(data);
//设置Data属性
intent.setData(uri);
startActivity(intent);
}
}); Button call=(Button)findViewById(R.id.call);
//为edit按钮添加一个监听器
call.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//创建Intent
Intent intent=new Intent();
//为Intent设置Action属性(动作为:拨号)
intent.setAction(Intent.ACTION_DIAL);
String data="tel:13800138000";
//根据指定字符串解析出Uri对象
Uri uri=Uri.parse(data);
//设置Data属性
intent.setData(uri);
startActivity(intent);
}
}); } @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.action_data, menu);
return true;
} }

运行上面的程序,单击第一个按钮,该按钮单击时启动Intent(Action=Intent.ACTION_VIEW,Data=http://www.crazyit.org)对应的Activity,将看到打开www.crazyit.org的界面,如图5.13所示。

单击第二个按钮,该按钮单击时启动Intent(Action=Intent.ACTION_EDIT,Data=content://com.android.contacts/contacts/1)对应的Activity,将看到编辑标识为1的联系人的界面。

单击第三个按钮,该按钮单击时启动Intent(Action=Intent.ACTION_DIAL,Data=tel:13800138000)对应的Activity,将看到程序向13800138000拨号的界面,如图5.15所示。

Intent的属性及Intent-filter配置——实例Action、Data属性启动系统Activity的更多相关文章

  1. Intent的属性及Intent-filter配置——指定Action、Category调用系统Activity

    Intent代表了启动某个程序组件的“意图”,实际上Intent对象不仅可以启动本应用内程序组件,也可启动Android系统的其他应用的程序组件,包括系统自带的程序组件——只要权限允许. 实际上And ...

  2. Python - 面向对象编程 - 类变量、实例变量/类属性、实例属性

    什么是对象和类 https://www.cnblogs.com/poloyy/p/15178423.html 什么是 Python 类.类对象.实例对象 https://www.cnblogs.com ...

  3. Struts2中配置默认Action

    1.当访问的Action不存在时,页面会显示错误信息,可以通过配置默认Action处理用户异常的操作:2.配置方法:    在struts.xml文件中的<package>下添加如下内容: ...

  4. JAVAEE学习——struts2_01:简介、搭建、架构、配置、action类详解和练习:客户列表

    一.struts2是什么 1.概念 2.struts2使用优势以及历史 二.搭建struts2框架 1.导包 (解压缩)struts2-blank.war就会看到 2.书写Action类 public ...

  5. html 5实用特性之data属性

    HTML 5之前,我们必须依赖于class和rel属性来存储需要在网站中使用的数据片段,这种做法有时会在网站的外观和实用性之间产生冲突.而HTML 5 Data属性的存在就能很好满足需要. HTML5 ...

  6. Kendo UI 初始化 Data 属性

    初始化 Data 属性 前面在介绍准备 Kendo UI 开发环境时我们使用 jQuery 的方法将一个  HTML 元素转换成一个 Kendo UI 控制项: $(“#datepicker”).ke ...

  7. HTML 5:你必须知道的data属性

    原文:All You Need to Know About the HTML5 Data Attribute 译文:你必须知道HTML 5 的Data属性 译者:dwqs HTML 5的Data属性可 ...

  8. Android中使用Intent的Action和Data属性实现点击按钮跳转到拨打电话和发送短信

    场景 点击拨打电话按钮,跳转到拨打电话页面 点击发送短信按钮,跳转到发送短信页面 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程 ...

  9. 在Android中Intent的概念及应用(一)——显示Intent和隐式Intent

    Intent寻找目标组件的两种方式: 显式Intent:通过指定Intent组件名称来实现的,它一般用在知道目标组件名称的前提下,一般是在相同的应用程序内部实现的. 隐式Intent:通过Intent ...

随机推荐

  1. UIApearance

    转载自:http://www.cocoachina.com/ios/20150723/12671.html 文章开头先援引一下Mattt Thompson大神在UIApearance里的一句话吧: 1 ...

  2. 搭建App主流框架_纯代码搭建(OC)

    转载自:http://my.oschina.net/hejunbinlan/blog/529778?fromerr=EmSuX7PR 搭建主流框架界面 源码地址在文章末尾 达成效果 效果图 注:本文部 ...

  3. UIView(包括子类)的几个初始化时执行动作的时机

    转载自:http://www.tqcto.com/article/mobile/56963.html 根据你需要执行的动作, 这里有几个方法: -(id)initWithFrame:(CGRect)f ...

  4. Python的import嵌套

    [root@fuel ~]# vi /var/lib/docker/devicemapper/mnt/4da57a0078c9d3f32e819373b67de41da37c34a27ee03f740 ...

  5. 超简单讲解JQ冒泡问题

    当JQ代码越写越长的时候,冒泡的问题就会显得突出.所以对JQ冒泡问题的了解是十分必要的. 那么什么是冒泡了,个人简单的理解就是在触发子元素事件的时候父元素的事件也被动触发. 举个简单例子: 例如有一个 ...

  6. Linux的iptables常用配置范例(2)

    iptables -F   #清除所有规则 iptables -X  #清除所有自定义规则 iptables -Z   #各项计数归零 iptables -P INPUT DROP  #将input链 ...

  7. losbyday Linux下的强大工具之一akw(转),Shell必备

    简单使用:awk :对于文件中一行行的独处来执行操作 .awk -F :'{print $1,$4}'   :使用‘:’来分割这一行,把这一行的第一第四个域打印出来 .  详细介绍:AWK命令介绍 a ...

  8. winscp 秘钥登录

    如题 如果不想用密码登录,可以选择用秘钥文件登录winscp 原理和linux分发ssh公钥是一个道理 1:在被管理的机器上分发公钥 ,出现 authorized_keys才可以 完成服务端配置 2: ...

  9. iOS开发实现Label中多颜色多字体

     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(8, 100, 300, 30)]; label.textColor = wor ...

  10. LIQN join on 后跟多个条件

    sql 版:SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredD ...