Android URI简介

2023-05-16



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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android URI简介 的相关文章

  • 改造中如何使用HashMap发布数据?

    您能解释一下如何使用以下方式发布数据吗hashmap in 改造2 这就是我发的帖子 FormUrlEncoded POST getProfile Call
  • 代码如何从 Android Gallery 加载图像

    我有用于从图库加载图像的代码 但我真的不明白它是如何工作的 这是代码 Override protected void onActivityResult int requestCode int resultCode Intent data s
  • 使用 android 将图像上传到 Flickr

    我需要将 Flickr 与 android 集成 我已完成身份验证 我需要将图像上传到 flickr 但我不知道如何执行相同操作 我参考文件 http www flickr com services api upload api html
  • Android 上的多处理

    我一直在 Android 上执行一些测试 以验证并行化算法 如 FFT 的性能可以提高多少 我通过使用带有 JNI FFTW 的 pthread 和 Java 线程 来自 JTransforms 来实现这些算法 我没有像预期那样通过使用线程
  • Android Studio 模拟器无法加载 Windows 10

    我在 Windows 10 上全新安装了 android studio 其中包含 android api 22 的所有软件包 当我运行模拟器时 我收到以下消息 C Users admin AppData Local Android sdk
  • Android 模拟器在 Windows 7 64 位上崩溃

    我是一名 Android 开发新手 到目前为止只在我的 Android 手机上运行了 Hello World 当我尝试在模拟器模式下运行我的应用程序时 我看到带有键盘和接听 挂断按钮的模拟器窗口 但在我的应用程序运行之前我收到一个窗口对话框
  • 尝试在谷歌地图V2 Android应用程序中获取空数组的长度

    我目前正在使用谷歌地图API开发一个Android应用程序 有时我会因为没有明显的原因而发生奇怪的崩溃 在我看来 这是崩溃日志 12 02 16 38 57 071 20796 21137 com appsolute ParkYoo E A
  • 检测Android N版本代码

    是否可以检测用户是否运行 Android N 我有一台装有 Android N 开发者预览版的 Nexus 6 如果我尝试获取构建版本Build VERSION SDK INT 它返回 23 等于 Android Marshmallow Q
  • Ionic4 电容器 android livereload?

    是否有可能在带有 livereload 的 Android 设备上运行带有电容器的 ionic 4 应用程序 我已经找了几个小时的答案了 但没有成功 请帮忙 如果使用最新版本 ionic cli 现在有一个命令ionic capacitor
  • Android Studio 与 Google Play 服务的编译问题

    我正在运行 Android Studio 0 8 4 并在 Android Studio 0 8 2 上尝试过此操作 我正在运行 Java JDK 1 8 0 11 并尝试使用 JDK 1 8 0 05 每当我尝试构建我的 android
  • 定时器时间不作为变量改变?

    这是我的代码 private int V Time 1 try final Timer V Timer final Handler V Handler V Timer new Timer V Handler new Handler Loop
  • 移动到SD卡

    我知道从 android 2 2 开始可以使用移动到 SD 卡功能 我想知道有没有办法在我的程序中检测设备是否支持移动到 SD 卡功能 如果支持 则可以移动 否则如果不支持 则什么也不会发生 将在手机内存中 我的主要问题是我的应用程序支持
  • 如何切换状态栏?

    我正在寻找一种显示和隐藏状态栏的方法onClickListener 但仅显示其有效 WindowManager LayoutParams lp getWindow getAttributes if isStatusbarVisible lp
  • 我怎样才能实现CoverFlow视图[关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我想用点线布局实现溢出视图 目前我正在使用 polidea 封面流库 URL github https
  • Android 10 中没有设备筛选器的 USB_DEVICE_ATTACHED

    我正在开发一个 Android 应用程序 它在清单中为 BroadcastReceiver 注册了四个意图过滤器 这些都是 android hardware usb action USB DEVICE ATTACHED android ha
  • 地理围栏不可用以及如何处理

    我正在 Android 上使用地理围栏 它在大多数手机上都工作正常 但在其中一些上 它不起作用 在我的错误日志中显示 地理围栏不可用 某些用户没有为 Google Play 服务启用位置跟踪 我认为这就是地理围栏在他们的手机上不起作用的原因
  • 在 Tensorflow-lite Android 中将位图转换为 ByteBuffer(浮点)

    在用于图像分类的tensorflow lite android演示代码中 图像首先转换为ByteBuffer格式以获得更好的性能 这种从位图到浮点格式的转换以及随后到字节缓冲区的转换似乎是一个昂贵的操作 循环 按位运算符 float mem
  • android中如何将字符串转换为unicode

    我正在解析一些unicodes from json to my android应用程序 API 给出unicodes像这样的图标 ue600 当我将这个unicode直接添加到textview like textview setText u
  • 如何获取视图到手机底部的距离?

    如果我在布局上有某个视图 ImageView 例如 是否可以找到View的下边框到手机屏幕底部的距离 Thanks instantiate DisplayMetrics DisplayMetrics dm new DisplayMetric
  • AsyncTask的并行执行

    An 异步任务单击时执行 List

随机推荐

  • Java Swing制作古老的打砖块游戏

    最近研究了一下古老的Java Swing xff0c 研究之余 xff0c 突发奇想开发了一个打砖块小游戏 首先看一下效果图 具体过程 1 游戏框架搭建1 1步骤 2 开发过程2 1各种游戏对象的绘制2 2游戏对象的运动2 3小球和砖块的碰
  • 局域网下yum代理配置

    需求背景 由于公司局域网内无法连接外网 xff0c 只有一台服务器能连接外网 xff0c 可选择搭建squid作为代理 xff0c 供无法访问外网的服务器 xff0c 安装软件使用 安装Squid yum install y squid 配
  • AndroidX迁移和吐槽

    最近引入一个第三方 xff0c 需要使用androidx扩展库 xff0c compile后发现与旧的support库无法兼容 xff0c 于是逐个的把support的库换成了androidx系列 xff0c 倒腾半天 xff0c 失败无数
  • Android中的事件

    有内容参考了别人的文章 xff0c 感谢作者 Input Events Event Listeners Event Handlers Touch Model Handling Focus https developer android co
  • Ubuntu19.10/20.04安装记录

    安装过程 官方网站下载 xff0c 搜索引擎搜索Ubuntu history version 找到19 10 xff0c 下载速度略慢 xff0c 大小大约2 3G 在Windows 上面使用UltraISO 试用版即可 刻录到u盘即可 重
  • android疑难问题收集

    1 自定义ViewGroup实现折叠展开 xff0c 离奇的折叠后又展开 在一个布局里面我参考网络代码实现了一个折叠展开的自定义viewgroup xff0c 其实是调用layout方法实现的折叠和展开 xff0c 最近出现一个bug xf
  • 开发错误笔记

    开发环境IDE Android Studio环境错误 1 布局引用的资源文件不存在的错误提示 Caused by android content res Resources NotFoundException Caused by org x
  • 程序员的送外卖经历

    今天我的一个朋友跟我发消息说 xff0c 看着外面刮着大风 xff0c 自己在屋子里面 xff0c 靠着暖气 xff0c 真是幸福啊 其实也没啥 xff0c 我这个朋友去年送了半年外卖 xff0c 大冬天依然在送 xff0c 户外骑着电动车
  • fragment添加失败错误查找

    根据源码查找原因 span class token class name Caused span by span class token operator span span class token class name span clas
  • Swing实现模仿HTML5模拟时钟特效

    自从研究了Java Swing的Graphics xff0c 觉得能按照自己的想法画出一些东西 xff0c 还是挺有意思的 xff0c 之前学习Java Swing的时候练习过一个模拟时钟 xff0c 自己觉得不错 xff0c 后来看到这个
  • jdk|adb命令行使用总结

    记录jdk的命令行使用记录 javac 1 java命令行编译多个源文件 javac d Example1 java Example2 java Example1是主类 xff0c 要用到Exmaple2 执行 xff1a java com
  • framework源码读后感

    View部分 1 ViewParent 今天查看了ViewGroup xff0c ViewRootImpl和ViewParent的部分源代码 xff0c 前面的两个类都实现了ViewParent接口 ViewGroup是一个抽象类 xff0
  • debian8 gnome 亮度调节

    debian8系统 xff0c 存在很多不兼容问题 xff0c 官方更新较慢 xff0c 但是电脑的硬件 xff0c 更新快 xff0c 很多驱动都无法在系统安装时给装好 xff0c 我装debian8系统时 xff0c 出了很多问题 例如
  • Android中图片占用内存的计算

    原帖 xff1a http blog csdn net hudashi article details 7856519 在Android开发中 xff0c 我现在发现很多人还不会对图片占用内存进行很好的计算 因此撰写该博文来做介绍 xff0
  • 自己写的Base64编码

    自己写的Base64编码函数非常蹩脚 xff0c 有待改进 发现有一个错误 不能拿着用 Base64转换用到了Java的位运算 amp gt gt lt lt gt gt gt a target blank href http zh wik
  • Android游戏开发想法

    1 想开发一个Android汉诺塔游戏 三个柱子 xff0c 一堆圆盘 xff0c 移动过来 xff0c 移动过去 必须大的在下 xff0c 小的在上 借助其中一根柱子移动到第三根柱子上 然而不知道从何做起 学习学习
  • 程序员谈学习:我为什么要学习Linux?

    好长时间没好好写点东西了 xff0c 前段时间由于项目的需要出差了一个多月 xff0c 期间各种加班 xff0c 每天晚上加班到十点 xff0c 回到宾馆实现是没什么精力再写博客了 有时间能静下来写点东西总是很好的一件事 xff0c 如果写
  • Android命令行创建项目并打包

    命令行创建Android项目 To create a new Android project open a command line navigate to the tools directory of your SDK and run a
  • FileTool.exe 替换 Visual C++ 的"打开"和"添加到项目中"的功能

    在Windows7中使用vc 43 43 6 0集成开发环境的时候 xff0c 当打开文件操作或者添加文件操作的时候vc会出错停止运行 xff0c 今天看了一个视频上面演示了解决办法 xff0c 地址 xff1a http v youku
  • Android URI简介

    xfeff xfeff 就Android平台而言 xff0c URI主要分三个部分 xff1a scheme authority and path 其中authority又分为host和port 格式如下 xff1a scheme host