以下是常用到的Intent的URI及其示例,包含了大部分应用中用到的共用Intent

一、打开一个网页,类别是Intent.ACTION_VIEW

1
2
Uri uri = Uri.parse("http://www.android-study.com/");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);

二、打开地图并定位到一个点

1
2
Uri uri = Uri.parse("geo:52.76,-79.0342");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);

三、打开拨号界面,类型是Intent.ACTION_DIAL

1
2
Uri uri = Uri.parse("tel:10086");
Intent intent = new Intent(Intent.ACTION_DIAL, uri);

四、直接拨打电话,与三不同的是,这个直接拨打电话,而不是打开拨号界面

1
2
Uri uri = Uri.parse("tel:10086");
Intent intent = new Intent(Intent.ACTION_CALL, uri);

五、卸载一个应用,Intent的类别是Intent.ACTION_DELETE

1
2
Uri uri = Uri.fromParts("package""xxx"null);
Intent intent = new Intent(Intent.ACTION_DELETE, uri);

六、安装应用程序,Intent的类别是Intent.ACTION_PACKAGE_ADDED

1
2
Uri uri = Uri.fromParts("package""xxx"null);
Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED, uri);

七、播放音频文件

1
2
3
Uri uri = Uri.parse("file:///sdcard/download/everything.mp3");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setType("audio/mp3");

八、打开发邮件界面

1
2
Uri uri= Uri.parse("mailto:admin@android-study.com");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);

九、发邮件,与八不同这里是将邮件发送出去

1
2
3
4
5
6
7
8
Intent intent = new Intent(Intent.ACTION_SEND);
String[] tos = { "admin@android-study.com" };
String[] ccs = { "webmaster@android-study.com" };
intent.putExtra(Intent.EXTRA_EMAIL, tos);
intent.putExtra(Intent.EXTRA_CC, ccs);
intent.putExtra(Intent.EXTRA_TEXT, "I come from http://www.android-study.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "http://www.android-study.com");intent.setType("message/rfc882");
Intent.createChooser(intent, "Choose Email Client");

//发送带附件的邮件

1
2
3
4
5
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
intent.putExtra(Intent.EXTRA_STREAM, "file:///sdcard/mysong.mp3");
intent.setType("audio/mp3");
startActivity(Intent.createChooser(intent, "Choose Email Client"));

十、发短信

1
2
3
4
Uri uri= Uri.parse("tel:10086");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.putExtra("sms_body""I come from http://www.android-study.com");
intent.setType("vnd.Android-dir/mms-sms");

十一、直接发短信

1
2
3
Uri uri= Uri.parse("smsto://100861");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body""3g android http://www.android-study.com");

十二、发彩信

1
2
3
4
5
Uri uri= Uri.parse("content://media/external/images/media/23");
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra("sms_body""3g android http://www.android-study.com");
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");

十三、# Market 相关

1
2
3
4
5
6
7
8
9
10
11
12
13
1 //寻找某个应用
Uri uri = Uri.parse("market://search?q=pname:pkg_name");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where pkg_name is the full package path for an application
 
2 //显示某个应用的相关信息
Uri uri = Uri.parse("market://details?id=app_id");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where app_id is the application ID, find the ID
//by clicking on your application on Market home
//page, and notice the ID from the address bar

十四、路径规划

1
2
3
4
Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
//where startLat, startLng, endLat, endLng are a long with 6 decimals like: 50.123456

十五、安装指定apk

1
2
3
4
5
6
public void setupAPK(String apkname){
    String fileName = Environment.getExternalStorageDirectory() + "/" + apkname;
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
    mService.startActivity(intent);
}

十六、进入联系人页面

1
2
3
4
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(People.CONTENT_URI);
startActivity(intent);

十七、查看指定联系人

1
2
3
4
5
Uri personUri = ContentUris.withAppendedId(People.CONTENT_URI, info.id);// info.id联系人ID
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(personUri);
startActivity(intent);

十八、调用相册

1
2
3
4
5
6
public static final String MIME_TYPE_IMAGE_JPEG = "image/*";
public static final int ACTIVITY_GET_IMAGE = 0;
Intent getImage = new Intent(Intent.ACTION_GET_CONTENT);
getImage.addCategory(Intent.CATEGORY_OPENABLE);
getImage.setType(MIME_TYPE_IMAGE_JPEG);
startActivityForResult(getImage, ACTIVITY_GET_IMAGE);

十九、调用系统相机应用程序,并存储拍下来的照片

1
2
3
4
5
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
time = Calendar.getInstance().getTimeInMillis();
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment
.getExternalStorageDirectory().getAbsolutePath()+"/tucue", time + ".jpg")));
startActivityForResult(intent, ACTIVITY_GET_CAMERA_IMAGE);

转:Intent 操作常用URI代码示例的更多相关文章

  1. SELECT控件操作的JS代码示例

    SELECT控件操作的JS代码示例 1 检测是否有选中 if(objSelect.selectedIndex > -1) { //说明选中 } else { //说明没有选中 } 2.动态创建s ...

  2. php操作redis常用方法代码示例

     redis 的连接 描述:实例连接到一个Redis. 参数:host: string,port: int 返回值:BOOL 成功返回:TRUE;失败返回:FALSE $redis = new Red ...

  3. python---Numpy模块中创建数组的常用方式代码示例

    要机器学习,这方面内容不可少. import numpy as np import time # 对比标准python实现和numpy实现的性能差异 def sum_trad(): start = t ...

  4. Python操作JSON数据代码示例

    #!/usr/bin/env python import json import os def json_test(): return_dic = {} json_data = { 'appid':' ...

  5. Android开发常用的Intent的URI及示例

    参考资料:http://www.oschina.net/code/snippet_166763_6502 //以下是常用到的Intent的URI及其示例,包含了大部分应用中用到的共用Intent. / ...

  6. Lambda表达式常用代码示例

    Lambda表达式常用代码示例 2017-10-24 目录 1 Lambda表达式是什么2 Lambda表达式语法3 函数式接口是什么  3.1 常用函数式接口4 Lambdas和Streams结合使 ...

  7. 生活常用类API调用的代码示例合集:邮编查询、今日热门新闻查询、区号查询等

    以下示例代码适用于 www.apishop.net 网站下的API,使用本文提及的接口调用代码示例前,您需要先申请相应的API服务. 邮编查询:通过邮编查询地名:通过地名查询邮编 今日热门新闻查询:提 ...

  8. 【嵌入式开发】裸机引导操作系统和ARM 内存操作 ( DRAM SRAM 类型 简介 | Logical Bank | 内存地址空间介绍 | 内存芯片连接方式 | 内存初始化 | 汇编代码示例 )

    [嵌入式开发]ARM 内存操作 ( DRAM SRAM 类型 简介 | Logical Bank | 内存地址空间介绍 | 内存芯片连接方式 | 内存初始化 | 汇编代码示例 )     一. 内存 ...

  9. Android总结篇——Intent机制详解及示例总结

         最近在进行android开发过程中,在将 Intent传递给调用的组件并完成组件的调用时遇到点困难,并且之前对Intent的学习也是一知半解,最近特意为此拿出一些时间,对Intent部分进行 ...

随机推荐

  1. 最大连续子数组和--dp

    最大连续子数组和 问题: 给定n个整数(可能为负数)组成的序列a[1],a[2],a[3],-,a[n],求该序列如a[i]+a[i+1]+-+a[j]的子段和的最大值.当所给的整数均为负数时定义子段 ...

  2. [hdu6978]New Equipments II

    显然可以费用流来做,具体建图如下-- 点集:源点,汇点,左边$n$​个工人,右边$n$​​​个设备 边集:源点向第$i$​个工人连$(1,a_{i})$​的边,第$i$​个设备向汇点连$(1,b_{i ...

  3. [atAGC049E]Increment Decrement

    由于每一个操作的逆操作都存在,可以看作将$a_{i}$全部变为0的代价 先考虑第一个问题,即对于确定的$a_{i}$如何处理 如果仅能用第2种操作,定义点$i$的代价为以$i$为左端点或以$i-1$为 ...

  4. 洛谷 P7360 -「JZOI-1」红包(Min-Max 容斥+推式子)

    洛谷题面传送门 hot tea. 首先注意到这个 \(\text{lcm}\) 特别棘手,并且这里的 \(k\) 大得离谱,我们也没办法直接枚举每个质因子的贡献来计算答案.不过考虑到如果我们把这里的 ...

  5. python 调用系统软件

    直接使用os模块的popen打开 import sys import os a=os.popen('/Soft/samtools-1.2/samtools flags '+sys.argv[1] ,' ...

  6. 64-Unique Binary Search Trees

    96. Unique Binary Search Trees My Submissions Question Editorial Solution Total Accepted: 82788 Tota ...

  7. yum和apt-get的用法和区别

    一般来说著名的linux系统基本上分两大类: 1.RedHat系列:Redhat.Centos.Fedora等 2.Debian系列:Debian.Ubuntu等 RedHat 系列 1 常见的安装包 ...

  8. Spring Security 基于URL的权限判断

    1.  FilterSecurityInterceptor 源码阅读 org.springframework.security.web.access.intercept.FilterSecurityI ...

  9. accelerate

    accelerate accelerare, accumulare和accurate共享一个含义为to的词根,后半截分别是:fast, pile up, care (关心则精确). 近/反义词: ex ...

  10. acupuncture

    acute+puncture. [woninstitute.edu稻糠亩] To understand the basics of acupuncture, it is best to familia ...