Android-Intent and Intent Filters
1.intent(意图)可以用来创建启动3种类型的基本情况:①To start an activity:启动一个活动②To start an service③To start an broadcast
2.intent types:-----first:Explicit intent:指的是当你知道你的类的名字,你可以使用显式意图,for instance:start an activity or start a service to download a file in background;
-----second:Implicit intent : 可以不指定一个明确的名字,采用一个明确的action 来指定要执行的操作,当其他的apps获取到这个action后执行所代表的动作,
他会在清单文件中看看那个能接受这个action。
PS:当启动一个service时,必须用显式意图!
3.如果一个隐式意图未被其他的程序处理,在startActivity()方法调用时,程序将崩溃
4.PendingIntent可用作三种情况:①通知信息的Intent②Home Screen的Intent,(app widget:应用程序小部件)③定义将来某个时间执行的代码。e.gAlarmManager
5.PendingIntent.getActivity() for an Intent that starts an Activity.
PendingIntent.getService()for anIntentthat starts aService.
PendingIntent.getBroadcast()for aIntentthat starts anBroadcastReceiver.
6.Alarm Clock(闹钟),创建一个闹钟,使用ACTION_SET_ALARM:
EXTRA_RINGTONEA content: URI specifying a ringtone to use with the alarm,or VALUE_RINGTONE_SILENT for no ringtone.
To use the default ringtone, do not specify this extra.
EXTRA_VIBRATEA boolean specifying whether to vibrate for this alarm.
EXTRA_SKIP_UIA boolean specifying whether the responding app should skip its UI when setting the alarm. If true, the app should bypass any confirmation UI and simply set the specified alarm.
显式
public void createAlarm(String message, int hour, int minutes) {
Intent intent = new Intent(AlarmClock.ACTION_SET_ALARM)
.putExtra(AlarmClock.EXTRA_MESSAGE, message)
.putExtra(AlarmClock.EXTRA_HOUR, hour)
.putExtra(AlarmClock.EXTRA_MINUTES, minutes);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
<uses-permission android:name="com.android.alarm.permission.SET_ALARM" />
隐式
<activity ...>
<intent-filter>
<action android:name="android.intent.action.SET_ALARM" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
7.Create a timer(定时器)创建一个倒计时定时器ACTION_SET_TIMER(PS:最低支持版本Android4.4)
public void startTimer(String message, int seconds) {
Intent intent = new Intent(AlarmClock.ACTION_SET_TIMER)
.putExtra(AlarmClock.EXTRA_MESSAGE, message)
.putExtra(AlarmClock.EXTRA_LENGTH, seconds)
.putExtra(AlarmClock.EXTRA_SKIP_UI, true); //true 表示不跳转到定时器界面
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
其他如上...
8.Show all alarms(显示所有闹钟)ACTION_SHOW_ALARMS
<activity ...>
<intent-filter>
<action android:name="android.intent.action.SHOW_ALARMS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
只有一个隐式声明意图
9.Add a calender event(在用户的日历中增加新事件)action:ACTION_INSERT
public void addEvent(String title, String location, Calendar begin, Calendar end) {
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(Events.CONTENT_URI)
.putExtra(Events.TITLE, title)
.putExtra(Events.EVENT_LOCATION, location)
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, begin)
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
<activity ...>
<intent-filter>
<action android:name="android.intent.action.INSERT" />
<data android:mimeType="vnd.android.cursor.dir/event" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

Android-Intent and Intent Filters的更多相关文章
- Android开发-API指南-Intent和Intent过滤器
Intents and Intent Filters 英文原文:http://developer.android.com/guide/components/intents-filters.html 采 ...
- android intent和intent action大全
1.Intent的用法:(1)用Action跳转1,使用Action跳转,如果有一个程序的AndroidManifest.xml中的某一个 Activity的IntentFilter段中 定义了包含了 ...
- Android安全之Intent Scheme Url攻击
0X01 前言 Intent scheme url是一种用于在web页面中启动终端app activity的特殊URL,在针对intent scheme URL攻击大爆发之前,很多android的浏览 ...
- Intent和Intent Filters
什么是Intent Intent是android开发中的重要对象,它作为一个信息承载对象存在. 我们可以在使用其他一些组件的时候从Intent获取行为响应的准则(即应该做什么东西,如何 ...
- Android复习笔记--Intent
Intent是Android中各组件跳转的重要方式,一般可悲用于启动活动.启动服务.以及发送广播等场景. #显示Intent 主要主要用于启动已知的组件 //发送方 Intent intent = ...
- Android 中的 Intent 简介
Intent是Android程序中各组件之间进行交互的一种重要方式,它不仅可以指明当前组件想要执行的动作,还可以在不同组件之间传递数据. ------------------------------- ...
- Android开发之Intent略解
Intent是一种运行时绑定(run-time binding)机制,它能在程序运行过程中连接两个不同的组件.通过Intent,你的程序可以向Android表达某种请求或者意愿,Android会根据意 ...
- Android学习之 Intent详解
一. Intent 作用 Intent 是一个将要执行的动作的抽象的描述,一般来说是作为参数来使用,由Intent来协助完成android各个组件之间的通讯.比如说调用startActivity()来 ...
- Android中的Intent Filter匹配规则介绍
本文主要介绍了隐式Intent匹配目标组件的规则,若有叙述不清晰或是不准确的地方希望大家指出,谢谢大家: ) 1. Intent简介 Intent用于在一个组件(Component,如Activity ...
- Android中的Intent详解
前言: 每个应用程序都有若干个Activity组成,每一个Activity都是一个应用程序与用户进行交互的窗口,呈现不同的交互界面.因为每一个Acticity的任务不一样,所以经常互在各个Activi ...
随机推荐
- MVC 感触
这几天接触了下 ef+ MVC+WEBAPI +bootstrop VIEW--->Controller -->WebAPI ---Model (Linq) 记住 VIEW里的 csh ...
- jsp 接收汉字参数乱码
这两天跟汉字问题较上劲了,真是考验基本功 1. ${param.userName} 乱码 解决方法: <%String name = (String)request.getParameter( ...
- 1-docker基础
docker有三个基本概念:镜像/容器/仓库 镜像:一个完整的root文件系统,但并非一个iso的打包文件,而是使用分层存储.构建镜像时,是一层一层的.新的镜像,也可以在原有镜像上添加新层. 容器:是 ...
- URAL 1890 . Money out of Thin Air (dfs序hash + 线段树)
题目链接: URAL 1890 . Money out of Thin Air 题目描述: 给出一个公司里面上司和下级的附属关系,还有每一个人的工资,然后有两种询问: 1:employee x y z ...
- Codeforces Round #395 (Div. 2) D
Description One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On t ...
- rac 添加 资源
10g : 自动化.监控.os,存储,底成,网络,规范
- 记录两个python itchat的用法博客网址
http://www.tuicool.com/articles/VJZRRfn https://itchat.readthedocs.io/zh/latest/
- ISCSI存储
slave-147作为服务端 需要安装的软件 [root@slave-147 ~]# yum install -y scsi-target-utils slave-148和slave-149作为客户端 ...
- border 0px和border none的区别
border:0px这个表示的是边框为0像素,表示边框的像素 border:none 这个表示无边框(边框的绘制方式),边框的绘制方式有很多种:solid dashed等等
- 滚动字幕Marquee
基本语法 <marquee>滚动文字 </marquee> 文字移动属性的设置 方向 <direction=#> #=left, right,up,down 方 ...