就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. Codeforces 474F - Ant colony

    注意到每个区间生存下来的蚂蚁的长度等于区间的gcd 于是可以先预处理出区间的gcd 然后二分查找就好了 预处理gcd我这里用的是倍增法 总的时间复杂度O(NlogN) /* Cf 271F 倍增求区间 ...

  2. web版扫雷小游戏(二)

    接上篇~~第一次写这种技术博客,发现把自己做的东西介绍出来还是一件脑力活,不是那么轻松啊,好吧,想到哪写到哪,流水记录之,待完成之后再根据大家的意见进行修改吧. 游戏实现 根据对扫雷游戏的体验和分析, ...

  3. Html5新增加的属性

    用2中方法给单复选框增加新的特性,使直接点击文字就可以被选中 1.将选项放入label标签内添加for属性,并在input标签内添加id,两者值相同. 2.将input标签放到label标签内,注意l ...

  4. 使用Slip.js快速创建整屏滑动的手机网页

    原文  http://segmentfault.com/blog/laopopo/1190000000708417 现在滑屏网页越来越多,比如我在搜狐视频就做了好几个,举个例子,可以用手机扫描以下的二 ...

  5. python之正则表达式备忘

    一简介:就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译成一系列的字节码,然后由用 C ...

  6. bzoj3639: Query on a tree VII

    Description You are given a tree (an acyclic undirected connected graph) with n nodes. The tree node ...

  7. ios新特征 ARC详解

    IOS ARC 分类: IOS ARC2013-01-17 09:16 2069人阅读 评论(0) 收藏 举报   目录(?)[+]   关闭工程的ARC(Automatic Reference Co ...

  8. Mosquitto-MQTT

    安装Mosquitto #To use the new repository you should first import the repository package signing key: w ...

  9. 修改weblogic jvm启动参数

    进入: D:\Oracle\Middleware\user_projects\domains\base_domain\startWebLogic.cmd 在call 上一行增加: set USER_M ...

  10. Dungeon Master

    poj2251:http://poj.org/problem?id=2251 题意:给你一个三维的立方体,然后给你一个起点,和终点的坐标.然后让你求从起点到终点的最短路程.题解:该题就是求三维的最短路 ...