就Android平台而言,URI主要分三个部分:scheme, authority and path。当中authority又分为host和port。格式例如以下:

scheme://host:port/path

举个实际的样例:

content://com.example.project:200/folder/subfolder/etc

\---------/  \---------------------------/ \---/ \--------------------------/

scheme                 host               port        path

                \--------------------------------/

                          authority   



如今大家应该知道data flag中那些属性的含义了吧,看下data flag

<data android:host="string"

      android:mimeType="string"

      android:path="string"

      android:pathPattern="string"

      android:pathPrefix="string"

      android:port="string"

      android:scheme="string" />

可是我们在程序中通常是不直接用URI来标识CP的,是的,正如我们通常见到的用定义的常量来标识。比如standard CP中的Contacts,我们就用Contacts.People.CONTENT_URI来标识Contacts CP中People这个表。那么要标识某个详细的人怎么办呢? 这就用到了ContentUris.withAppendedId() 和 Uri.withAppendedPath()。比如我们要表示content://contacts/people/20,那么我们就能够用例如以下语句:

Uri uri = ContentUris.withAppendedId(People.CONTENT_URI, 20); 或者

Uri uri = Uri.withAppendedPath(People.CONTENT_URI, "20");

举些样例,如:

全部联系人的Uri: content://contacts/people

某个联系人的Uri: content://contacts/people/5

全部图片Uri: content://media/external

某个图片的Uri:content://media/external/images/media/4

以下是一些经常使用的Uri

显示网页:

  1. Uri uri = Uri.parse("http://www.google.com");

  2. Intent it = new Intent(Intent.ACTION_VIEW,uri);

  3. startActivity(it);



显示地图:

1. Uri uri = Uri.parse("geo:38.899533,-77.036476");

  2. Intent it = new Intent(Intent.Action_VIEW,uri);

  3. startActivity(it);



路径规划:

  1. Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr=startLat%20startLng&daddr=endLat%20endLng&hl=en");

  2. Intent it = new Intent(Intent.ACTION_VIEW,URI);

  3. startActivity(it);



拨打电话:

调用拨号程序

  1. Uri uri = Uri.parse("tel:xxxxxx");

  2. Intent it = new Intent(Intent.ACTION_DIAL, uri);  

  3. startActivity(it);  

  1. Uri uri = Uri.parse("tel.xxxxxx");

  2. Intent it =new Intent(Intent.ACTION_CALL,uri);

  3. 要使用这个必须在配置文件里增加<uses-permission id="Android.permission.CALL_PHONE" />



发送SMS/MMS

调用发送短信的程序

  1. Intent it = new Intent(Intent.ACTION_VIEW);

  2. it.putExtra("sms_body", "The SMS text");

  3. it.setType("vnd.android-dir/mms-sms");

  4. startActivity(it);  

发送短信

  1. Uri uri = Uri.parse("smsto:0800000123");

  2. Intent it = new Intent(Intent.ACTION_SENDTO, uri);

  3. it.putExtra("sms_body", "The SMS text");

  4. startActivity(it);  

发送彩信

  1. Uri uri = Uri.parse("content://media/external/images/media/23");

  2. Intent it = new Intent(Intent.ACTION_SEND);

  3. it.putExtra("sms_body", "some text");

  4. it.putExtra(Intent.EXTRA_STREAM, uri);

  5. it.setType("image/png");

  6. startActivity(it);



发送Email

  1.

  2. Uri uri = Uri.parse("mailto:xxx@abc.com");

  3. Intent it = new Intent(Intent.ACTION_SENDTO, uri);

  4. startActivity(it);

  1. Intent it = new Intent(Intent.ACTION_SEND);

  2. it.putExtra(Intent.EXTRA_EMAIL, "me@abc.com");

  3. it.putExtra(Intent.EXTRA_TEXT, "The email body text");

  4. it.setType("text/plain");

  5. startActivity(Intent.createChooser(it, "Choose Email Client"));  

  1. Intent it=new Intent(Intent.ACTION_SEND);  

  2. String[] tos={"me@abc.com"};  

  3. String[] ccs={"you@abc.com"};  

  4. it.putExtra(Intent.EXTRA_EMAIL, tos);  

  5. it.putExtra(Intent.EXTRA_CC, ccs);  

  6. it.putExtra(Intent.EXTRA_TEXT, "The email body text");  

  7. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");  

  8. it.setType("message/rfc822");  

  9. startActivity(Intent.createChooser(it, "Choose Email Client"));



加入附件

  1. Intent it = new Intent(Intent.ACTION_SEND);

  2. it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");

  3. it.putExtra(Intent.EXTRA_STREAM, "[url=]file:///sdcard/mysong.mp3[/url]");

  4. sendIntent.setType("audio/mp3");

  5. startActivity(Intent.createChooser(it, "Choose Email Client"));



播放多媒体

  1.  

  2. Intent it = new Intent(Intent.ACTION_VIEW);

  3. Uri uri = Uri.parse("[url=]file:///sdcard/song.mp3[/url]");

  4. it.setDataAndType(uri, "audio/mp3");

  5. startActivity(it);

  1. Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");

  2. Intent it = new Intent(Intent.ACTION_VIEW, uri);

  3. startActivity(it);  



Uninstall 程序

  1. Uri uri = Uri.fromParts("package", strPackageName, null);

  2. Intent it = new Intent(Intent.ACTION_DELETE, uri);

  3. startActivity(it);



//调用相冊

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);



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

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);



uninstall apk

/**未測试

Uri uninstallUri = Uri.fromParts("package", "xxx", null);

returnIt = new Intent(Intent.ACTION_DELETE, uninstallUri);

*/

Uri packageURI = Uri.parse("package:"+wistatmap);  

Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);  

startActivity(uninstallIntent);



install apk

Uri installUri = Uri.fromParts("package", "xxx", null);

returnIt = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri);

play audio

Uri playUri = Uri.parse("[url=]file:///sdcard/download/everything.mp3[/url]");

returnIt = new Intent(Intent.ACTION_VIEW, playUri);



//发送附件

Intent it = new Intent(Intent.ACTION_SEND);  

it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");  

it.putExtra(Intent.EXTRA_STREAM, "[url=]file:///sdcard/eoe.mp3[/url]");  

sendIntent.setType("audio/mp3");  

startActivity(Intent.createChooser(it, "Choose Email Client"));



//搜索应用

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



//进入联系人页面

Intent intent = new Intent();

intent.setAction(Intent.ACTION_VIEW);

intent.setData(People.CONTENT_URI);

startActivity(intent);



//查看指定联系人

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);

Android URI简单介绍的更多相关文章

  1. Android发展简单介绍

    Android一词的本义指“机器人”,同一时候也是Google于2007年11月5日宣布的基于Linux平台的开源手机操作系统的名称,该平台由操作系统.中间件.用户界面和应用软件组成,号称是首个为移动 ...

  2. Android NDK 简单介绍、工具安装、环境配置

    NDK全称:Native Development Kit. 1.NDK是一系列工具的集合. * NDK提供了一系列的工具,帮助开发人员高速开发C(或C++)的动态库,并能自己主动将so和java应用一 ...

  3. 值得推荐的android开发框架简单介绍

    一些总结出来的Android高速开发框架,所有都是开源框架,附带项目地址,是开发学习的绝佳资料. Direct-Load-apk项目 项目主页地址:http://www.kymjs.com/ 功能:D ...

  4. Android Studio 简单介绍和使用问题小结

    原文  http://www.cnphp6.com/archives/59264 主题 Gradle Android Studio Android 随着android 5.0 的发布,android ...

  5. android ViewStub简单介绍

    ViewStub是一种非常灵活的视图,主要用于布局资源的实时加载. ViewStub 的继承类关系如下: public final class ViewStubextends View java.la ...

  6. Android ImageLoader(Android-Universal-Image-Loader)【1】概述及使用简单介绍

     Android ImageLoader(Android-Universal-Image-Loader)[1]概述及使用简单介绍 一,前言:为什么要引入Android-Universal-Imag ...

  7. Android中Intent具体解释(二)之使用Intent广播事件及Broadcast Receiver简单介绍

    通过第一篇的解说,我们已经看到了怎样使用Intent来启动新的应用程序组件,可是实际上他们也能够使用sendBroadcast方法来在组件间匿名的广播消息. 作为一个系统级别的消息传递机制,Inten ...

  8. Android开发自学笔记(Android Studio)—4.界面编程与View组件简单介绍

    一.引言 Android应用开发最重要的一份内容就是界面的开发,无论你程序包含的内容多么优秀,如若没有一个良好的用户交互界面,最终也只是会被用户所遗弃.Android SDK提供了大量功能丰富的UI组 ...

  9. Android项目开发全程(二)--Afinal用法简单介绍

    本篇博文接上篇的<Android项目开发全程(一)--创建工程>,主要介绍一下在本项目中用到的一个很重要的框架-Afinal,由于本系列博文重点是项目开发全程,所以在这里就先介绍一下本项目 ...

随机推荐

  1. 改进《完美让IE兼容input placeholder属性的jquery实现》的不完美

    <完美让IE兼容input placeholder属性的jquery实现>中的代码在IE9以下浏览器中会出错,原因是因为ie9以下的浏览器对input的标签的解释不同. 例如对以下文本框的 ...

  2. 【POJ1823】【线段树】Hotel

    Description The "Informatics" hotel is one of the most luxurious hotels from Galaciuc. A l ...

  3. Java多线程:Semaphore

    Semaphore为并发包中提供用于控制某资源同时可以被几个线程访问的类 实例代码: // 允许2个线程同时访问 final Semaphore semaphore = new Semaphore(2 ...

  4. WIN7下运行hadoop程序报:Failed to locate the winutils binary in the hadoop binary path

    之前在mac上调试hadoop程序(mac之前配置过hadoop环境)一直都是正常的.因为工作需要,需要在windows上先调试该程序,然后再转到linux下.程序运行的过程中,报Failed to ...

  5. One-day-学习笔记-商品成交时发送短信

    个人学习笔记(one) 根据需求:商品成交时发送短信 html代码省略..... Model代码省略..... /* * --------------------------------------- ...

  6. QTP插入Output Value和插入CheckPoint,注意点

    1. 必须打开程序才能进行Output value和CheckPoint的插入. 2. 也有可能是对象获取不到,从新加载对象库. 提示如下图:

  7. ecshop数据库操作类

    ECShop v2.7.2没有使用一些开源的数据库操作类,比如adodb或者PEAR,而是封装了自己的实现. 好处:实现非常轻量,只有一个文件,27Kb,大大减小了分发包的文件大小. 当网站需要做me ...

  8. nginx 编译选项

    内容有些多,一眼看来难免头昏脑胀,但坚持看完,相信你一定会有所收获. nginx参数: --prefix= 指向安装目录 --sbin-path 指向(执行)程序文件(nginx) --conf-pa ...

  9. 使用jQuery UI方法

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. [BZOJ 3172] [Tjoi2013] 单词 【AC自动机】

    题目链接:BZOJ - 3172 题目分析: 题目要求求出每个单词出现的次数,如果把每个单词都在AC自动机里直接跑一遍,复杂度会很高. 这里使用AC自动机的“副产品”——Fail树,Fail树的一个性 ...