就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 Round #287 D.The Maths Lecture

    The Maths Lecture 题意:求存在后缀Si mod k =0,的n位数的数目.(n <=1000,k<=100); 用f[i][j]代表 长为i位,模k等于j的数的个数. 可 ...

  2. Qt Creator编译问题

    有时候需要自己编译Qt Creator,需要注意的就是qmake版本的问题,比如我用4.8.1和4.8.6同样编译出来的Qt Creator在同样的qtconfig-qt4下所呈现的效果是不一样的. ...

  3. HTML5画布

  4. 网页布局只mian部分左右固定,中间部分自适应

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. 入门1:PHP的优点

    一.语法简单 二.学习成本低 (因为语法简单 所以学习成本低) 三.开发效率高 (PHP运行流程很简单,语法也很简单,必然开发效率就高) 四.跨平台 (我们只需要写一份PHP的程序,就可以非常方便的把 ...

  6. QTP的DataTable操作整理(注---不知转载多少遍)

    返回值:数字 示例: 以下示例使用 GetRowCount 方法查找 MySheet 运行时数据表中最长的列中的总行数,并将其写入报告. rowcount = DataTable.GetSheet(& ...

  7. Day10 网络编程(续)

    作用域 Python的作用域是函数,没有块级作用域 if 1 == 1: name = 'wang' print(name) #wang   for i in range(10): name = i ...

  8. linux中ls、ls -l、ls -al、ll命令

    ls只是简单的列出目录下文件名,ll更加详细的列出了文件的类型.文件所有者权限.文件所有者组权限.文件大小.文件最后修改时间,etc... 我们可以用一个简单的图来说明,如下图1: 图1 1.第一位就 ...

  9. 使用date命令,进行时间戳和日期时间的互转

    首先是知道时间转成时间戳 date -d "2014-01-16 12:30:11" +%s - :: - :: 其次是知道时间戳,想要知道当时的时间 date -d '1970- ...

  10. C++例题2:汉诺塔问题

    #include<iostream>#include<stdlib.h>using namespace std;void Hanoi(int n,char A,char B,c ...