转:intent简介

摘要:
传输自:此处-Android系统中的Standard Intent1 for Activity根据联系人ID[java]viewplaincopyIntent=newIntent()显示联系人信息;intent.setAction(intent.ACTION_VIEW);//显示联系人信息意图。setData(Uri.parse(“content://contacts/people/492 "));

转自:here

一 Android系统用于Activity的标准Intent

 
1 根据联系人ID显示联系人信息
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_VIEW);   //显示联系人信息  
  3. intent.setData(Uri.parse("content://contacts/people/492"));  
  4. startActivity(intent);  

2 根据联系人ID显示拨号面板
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_DIAL);  //显示拨号面板  
  3. intent.setData(Uri.parse("content://contacts/people/492"));  
  4. startActivity(intent);  

3 显示拨号面板, 并在拨号面板上将号码显示出来
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_VIEW);     
  3. intent.setData(Uri.parse("tel://15216448315"));  
  4. startActivity(intent);  

4 显示拨号面板, 并在拨号面板上将号码显示出来
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_DIAL);   //显示拨号面板, 并在拨号面板上将号码显示出来  
  3. intent.setData(Uri.parse("tel://15216448315"));  
  4. startActivity(intent);  

5 根据联系人的ID编辑联系人
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_EDIT);   //编辑联系人  
  3. intent.setData(Uri.parse("content://contacts/people/492"));  
  4. startActivity(intent);  

6 显示通讯录联系人和其他账号联系人的列表
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_VIEW);     
  3. intent.setData(Uri.parse("content://contacts/people/"));  
  4. startActivity(intent);  

7 启动HomeScreen
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_MAIN);     //启动HomeScreen  
  3. intent.addCategory(Intent.CATEGORY_HOME);  
  4. startActivity(intent);  

8 选择某个联系人的号码,返回一个代表这个号码的uri,如:content://contacts/phones/982
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_GET_CONTENT);       
  3. intent.setType("vnd.android.cursor.item/phone");  
  4. startActivityForResult(intent, 1);  

9  打开多个应用选取各种类型的数据,以uri返回。返回的uri可使用ContentResolver.openInputStream(Uri)打开
    该功能可用在邮件中附件的选取
    举例如下:
    选取一张图片, 返回的uri为 content://media/external/images/media/47
    选取一首歌, 返回的uri为 content://media/external/audio/media/51
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_GET_CONTENT);       
  3. intent.setType("*/*");  
  4. intent.addCategory(Intent.CATEGORY_OPENABLE);  
  5. startActivityForResult(intent, 2);  

10 自定义一个chooser,不使用系统的chooser
     该chooser可以有自己的标题(Title)
     并且不必让用户指定偏好
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_CHOOSER);   
  3. intent.putExtra(Intent.EXTRA_TITLE, "my chooser");  
  4. intent.putExtra(Intent.EXTRA_INTENT,   
  5.         new Intent(Intent.ACTION_GET_CONTENT)  
  6.         .setType("*/*")  
  7.         .addCategory(Intent.CATEGORY_OPENABLE)  
  8.         );  
  9.   
  10. startActivityForResult(intent, 2);  

11 选取activity,返回的activity可在返回的intent.getComponent()中得到
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_PICK_ACTIVITY);   
  3. intent.putExtra( Intent.EXTRA_INTENT,   
  4.         new Intent(Intent.ACTION_GET_CONTENT)  
  5.         .setType("*/*")  
  6.         .addCategory(Intent.CATEGORY_OPENABLE)  
  7.         );  
  8. startActivityForResult(intent, 3);  

12 启动搜索,在以下示例代码中,"ANDROID"为要搜索的字符串
     当执行这段代码后, 会在系统的Chooser中显示可以用于搜索的程序列表
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_SEARCH);     //启动搜索  
  3. intent.putExtra(SearchManager.QUERY, "ANDROID");  
  4. startActivity(intent);  

13 启动WEB搜索,在以下示例代码中,"ANDROID"为要搜索的字符串
     当执行这段代码后, 会在系统的Chooser中显示可以用于搜索的程序列表,一般情况下系统中安装的浏览器都会显示出来
[java] view plaincopy
 
  1. Intent intent = new Intent();  
  2. intent.setAction(Intent.ACTION_WEB_SEARCH);     //启动搜索  
  3. intent.putExtra(SearchManager.QUERY, "ANDROID");  
  4. startActivity(intent);  
 

二  Android系统用于BroadcastReceiver的标准Intent

 
1 ACTION_TIME_TICK,系统时钟广播,系统每分钟都会发送一个这样的广播,
   如果在应用开发中,有些逻辑依赖于系统时钟,可以注册一个广播接收者
   这是一个受保护的action,只有系统才能发送这个广播
   并且,在manifest文件中注册的广播接收者不能接收到该广播,若要接收该广播,必须在代码中注册广播接收者
[java] view plaincopy
 
  1. registerReceiver(new BroadcastReceiver(){  
  2.   
  3.     @Override  
  4.     public void onReceive(Context context, Intent intent) {  
  5.         Log.i("xxxx", "TIME_TICK");  
  6.     }  
  7.       
  8. },   
  9. new IntentFilter(Intent.ACTION_TIME_TICK));  

2 在官方文档中,列出了以下标准的广播action

三  Android中的标准类别(category)

 
类别(category)一般配合action使用,以下为系统中的标准类别,由于数量过多,只能在使用到时再详细研究

四  Android中的标准Extra键值

 
这些常量用于在调用Intent.putExtra(String, Bundle)时作为键值传递数据,同样由于数量较多,在此只列出索引

五  Intent中的标志(FLAG)

 
Intent类中定义了一些以FLAG_开头的标志位,这些标志位中有的非常重要,会影响app中Activity和BroadcastReceiver等的行为。
以下为这些标志位的索引,是从官方文档上的截图。之后会对重要的标志加以详细分析
转:intent简介第1张
转:intent简介第2张

免责声明:文章转载自《转:intent简介》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇sqlserver 实现数据变动触发信息selenium模拟鼠标操作下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Unity2019使用Gradle命令行(编译)出安卓包

在我所经历的项目组中有这几种方法来生成APK 直接在Unity生成APK,可以接入SDK 使用Unity导出Android Studio工程手动生成APK 使用Unity导出Android Studio工程命令行离线生成APK 这里记录一下我在项目组使用Android Studio出包的笔记。 使用Unity导出Android Studio工程前建议查...

Android 广播大全

本文摘自http://www.cppcode.com/archives/2012/03/13/181.html Android 广播大全   Intent.ACTION_AIRPLANE_MODE_CHANGED; ——关闭或打开飞行模式时的广播   Intent.ACTION_BATTERY_CHANGED; ——充电状态,或者电池的电量发生变化 ——电池...

安卓渗透和审计工具整理

1.cSploit: https://github.com/cSploit/android/releases 2.DroidSheephttp://bbs.zhiyoo.com/thread-13249611-1-1.html 3.androrathttps://github.com/wszf/androrat 4.Network Spoofhttps:/...

Android 自定义CheckBox 样式

新建Android XML文件,类型选Drawable,根结点选selector,在这定义具体的样式。 <?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">...

Android环境配置和移动自动化(Genymotion)相关配置

本机环境: Window10 其他材料准备: 安卓开发者网站(AndroidStudio下载-3.6.3) 安卓开发工具网站(SDKTools下载-android-sdk_r24.4.1-windows.zip) Genymotion模拟器下载(如果未安装VirtualBox 虚拟机, 选择with VirtualBox-genymotion-3.1.0...

Android怎样设置圆角button

1. 在res文件夹下的drawable文件夹下新建shape.xml文件 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectan...