Android系统中Intent的使用

1.根据联系人ID显示联系人信息

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_VIEW);   //显示联系人信息  
intent.setData(Uri.parse("content://contacts/people/492"));  
startActivity(intent);  

2.根据联系人ID显示拨号面板

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_DIAL);  //显示拨号面板  
intent.setData(Uri.parse("content://contacts/people/492"));  
startActivity(intent);  

3.显示拨号面板, 并在拨号面板上将号码显示出来

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_VIEW);     
intent.setData(Uri.parse("tel://15216448315"));  
startActivity(intent);  

4.显示拨号面板, 并在拨号面板上将号码显示出来

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_DIAL);   //显示拨号面板, 并在拨号面板上将号码显示出来  
intent.setData(Uri.parse("tel://15216448315"));  
startActivity(intent);

5.根据联系人的ID编辑联系人

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_EDIT);   //编辑联系人  
intent.setData(Uri.parse("content://contacts/people/492"));  
startActivity(intent);  

6.显示通讯录联系人和其他账号联系人的列表

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_VIEW);     
intent.setData(Uri.parse("content://contacts/people/"));  
startActivity(intent);  

7 启动HomeScreen

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_MAIN);     //启动HomeScreen  
intent.addCategory(Intent.CATEGORY_HOME);  
startActivity(intent);  

8 选择某个联系人的号码,返回一个代表这个号码的uri,如:content://contacts/phones/982

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_GET_CONTENT);       
intent.setType("vnd.android.cursor.item/phone");  
startActivityForResult(intent, 1); 

9 打开多个应用选取各种类型的数据,以uri返回。返回的uri可使用ContentResolver.openInputStream(Uri)打开 该功能可用在邮件中附件的选取
举例如下:
选取一张图片, 返回的uri为 content://media/external/images/media/47
选取一首歌, 返回的uri为 content://media/external/audio/media/51

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_GET_CONTENT);       
intent.setType("*/*");  
intent.addCategory(Intent.CATEGORY_OPENABLE);  
startActivityForResult(intent, 2);  

10 自定义一个chooser,不使用系统的chooser
该chooser可以有自己的标题(Title)
并且不必让用户指定偏好

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_CHOOSER);   
intent.putExtra(Intent.EXTRA_TITLE, "my chooser");  
intent.putExtra(Intent.EXTRA_INTENT,   
        new Intent(Intent.ACTION_GET_CONTENT)  
        .setType("*/*")  
        .addCategory(Intent.CATEGORY_OPENABLE)  
        );  

startActivityForResult(intent, 2);  

11 选取activity,返回的activity可在返回的intent.getComponent()中得到

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_PICK_ACTIVITY);   
intent.putExtra( Intent.EXTRA_INTENT,   
        new Intent(Intent.ACTION_GET_CONTENT)  
        .setType("*/*")  
        .addCategory(Intent.CATEGORY_OPENABLE)  
        );  
startActivityForResult(intent, 3);  

12 启动搜索,在以下示例代码中,”ANDROID”为要搜索的字符串
当执行这段代码后, 会在系统的Chooser中显示可以用于搜索的程序列表

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_SEARCH);     //启动搜索  
intent.putExtra(SearchManager.QUERY, "ANDROID");  
startActivity(intent);  

13 启动WEB搜索,在以下示例代码中,”ANDROID”为要搜索的字符串
当执行这段代码后, 会在系统的Chooser中显示可以用于搜索的程序列表,一般情况下系统中安装的浏览器都会显示出来

Intent intent = new Intent();  
intent.setAction(Intent.ACTION_WEB_SEARCH);     //启动搜索  
intent.putExtra(SearchManager.QUERY, "ANDROID");  
startActivity(intent);  

转自:http://blog.csdn.net/zhangjg_blog/article/details/10901293

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值