Android高版本的Uri及其使用注意问题

Android10/11/12/13 Uri与真实路径转换--全适配 /** * 根据Uri获取文件绝对路径,解决Android4.4以上版本Uri转换 * * @param context * @param imageUri */ public static String getFileAbsolutePath(Context context, Uri imageUri) { if (context == null || imageUri == null) { r... 阅读详情
AI摘要

本文介绍Android 10及以上版本中使用Uri进行文件操作的方法,包括文档标识、路径转换及文件删除等内容。

一、前言

Uri又被成为统一资源定位符。顾名思义,是用来定位资源的。在Android中主要是用来定位本地资源的。在Android10.0以前由于可以直接使用File进行文件读写,所以Uri的使用范围没那么广。只有使用存放在raw、asset或者其它资源文件时候,以及使用ContentProvider这些方式的时候才进行使用Uri。相对于整个项目来说,频率较低。但是

由于Android10.0开始强制逐步强制使用SAF的方式进行文档读写。因此Uri开始很频繁的被开发者进行使用。本篇文章对一些不同场景下Uri的生成和使用进行一个整理和总结。

二、Document

在Android中的文档体系中,Android把所有文档都用一个id进行标识。所以理论上知道id可以获取对应的位置,可以通过以下代码进行获取

ContentUris.withAppendedId(uri,id) 

下面是一个MediaStore示例:

  val mediaInfoList = arrayListOf<MediaInfo>()
        val uri = MediaStore.Files.getContentUri("external")
        val selection =
            "(" + MediaStore.Files.FileColumns.DATA + " LIKE '%ym_empty%'" + ")"
        val cursor: Cursor? = contentResolver.query(uri, null, selection, null, null)
        try {
            cursor!!.moveToFirst()
            while (!cursor.isAfterLast) {
                val id = cursor.getLong(cursor.getColumnIndex(MediaStore.Files.FileColumns._ID))
                val contentUri = ContentUris.withAppendedId(
                    uri,
                    id
                ) 
                cursor.moveToNext()
            }
        } catch (e: Exception) {
            e.printStackTrace()
        } finally {
            cursor?.close()
        }

这个链接的样子如下:

content://media/external/images/media/272

可以将该Uri转换为DocumentFile.

  val documentFile =
                    DocumentFile.fromSingleUri(RockeyApp.getInstance()!!, contentUri)

还有一种将File转换为DocumentFile的方式,如下:

比如文档的路径为/storage/emulated/0/Download/1-1604402012.png

val documentFile = DocumentFile.fromFile(file)

通过以上方式转换完的路径为
file:///storage/emulated/0/Download/1-1604402012.png

可以看到这个路径和之前的路径是不太一样的,但是依然可以正常使用。

另外通过这种方式转换的Uri可以再次转换为File,其余方式则不可以

val documentFile = DocumentFile.fromFile(file)
val newFile = documentFile.uri.toFile()

需要注意的是,在Android中有些文件其实不存在了,但是File.exists()依然会判断存在,这里使用DocumentFile.exists()函数才会返回正确结果

使用SAF获取的路径如下:

content://com.android.externalstorage.documents/tree/primary%3AAndroid%2Fmedia%2Fcom.whatsapp

可以看到这种路径和上面的也不太一样。

三、文件删除

上面已经知道可以通过File、id、SAF等方式转换成为DocumentFile。但是在执行删除操作时候却并不能都按照DocumentFile进行文件删除。还是需要使用各自的方式进行删除。只有使用SAF方式获取的文件可以使用DocumentFile进行删除。

1、File

val file = File(path)
file.delete()

2、MediaStore

val file = File(path)
val filePath = file.path
                    val res: Int = contentResolver.delete(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        MediaStore.Images.Media.DATA + "= \"" + filePath + "\"",
                        null
                    )

3、DocumentFile

val dirDocument =
   DocumentFile.fromSingleUri(RockeyApp.getInstance()!!, Uri.parse(fileStr))
   val isDel = dirDocument?.delete()

四、参考链接

  1. Uri

  2. Android中的Uri详解_JMW1407的博客-CSDN博客_android uri

  3. Is it possible to get a regular File from DocumentFile?

  4. DocumentFile  |  Android Developers

  5. DocumentsContract  |  Android Developers

  6. Storage Access Framework_光英的记忆博客-CSDN博客

  7. Android content 类型的 Uri 转换成绝对路径

ContentResolver操作uri权限问题 在Android中使用ContentResolver通过uri代开输入流: ContentResolver contentResolver = getContentResolver(); InputStream inputStream = contentResolver.openInputStream(uri); 报了以下错误: java.lang.SecurityException: Permission Denial: reading com.android.externalstorage.Exter 阅读详情

相关推荐

安卓webView使用到文件上传流遇到的问题

layout: post author: zjhChester header-img: img/post-bg-universe.jpg catalog: true tags: - android 安卓webView使用到文件上传流遇到的问题 前言: 做的h5网页可以直接套一个webView的壳子直接运行,但是如果里头有<input type='file'>的时候,需...

qq_38593205的博客 3220

android file path,Android之uri、file、path相互转化

1、uri转file:file = new File(new URI(uri.toString()));file转uri:URI uri = file.toURI();2、uri转path:private String getPath(Context context, Uri uri) {String path = null;Cursor cursor = context.getContentRe...

weixin_35888209的博客 2086

Android进阶之路 - Uri、Path、File、Bitmap 转换方式

在拍照和相册功能中经常能遇到一些uri、path、file、bitmap的相互转换问题,这里主要记录一些Uri、Path、File、Bitmap 转换方式

Android、前端、小程序、后端 1万+

Android file转Uri

使用ContentResolver提供的方法:如果您的应用程序需要在Android 4.3(API级别18)及更低版本上使用File对象,则可以使用ContentResolver的openFileDescriptor()方法将File对象转换为FileDescriptor对象,然后使用FileDescriptor转换为Uri对象的方法。这种方法适用于Android 4.4(API级别19)及更高版本。

lrl520panan1314的博客 1510

Android开发:Uri到File的转换与处理

通过上述方法,我们可以成功地将Uri转换为文件并读取其内容。这种方法虽然涉及到临时文件的创建和删除,但它提供了一种简单而有效的解决方案来处理content类型的Uri。在实际开发中,根据需求,我们也可以直接从输入流中读取数据,而不需要创建临时文件,这取决于具体的应用场景。

m0_74337424的博客 457

手把手教你用Python处理MAHNOB-HCI多模态数据集(含脑电EEG/眼动/视频数据同步实战)

本文详细介绍了如何使用Python处理MAHNOB-HCI多模态数据集,涵盖脑电(EEG)、眼动追踪和视频数据的同步解析与对齐。通过MNE-Python、pandas和OpenCV等工具,实现从BDF、TSV到XML格式的高效处理,解决时间轴对齐难题,助力情感计算与人机交互研究。

weixin_30998797的博客 386

Android系统的问题分析笔记(9) - Android 中的 Uri 如何使用呢 ?

通用资源标志符 URI (Universal Resource Identifier),URI 在 java.net.URI 中定义,显然是 Java 提供的一个类。而 Uri 位置在 android.net.Uri 中定义(Android 源码内位置:frameworks/base/core/java/android/net/Uri.java),是特有针对 Android 系统定义的类。Uri 代表要操作的数据,Android 上可用的每种资源(图像、视频片段、网页等)都可以用 Uri 来表示。

Android系统工程师--小馬佩德罗 4824

gradle报错:A problem occurred configuring root project ‘My Application‘.

即使翻译了,我开始也看不懂,到处找网上教程,但都是改环境变量。马虎的我即使看了很多遍,改了很多遍也没反应过来,今天第一次搞gradle,突然就报错了,打印出。好了我就继续看项目了。

m0_59878789的博客 4097

Uri详解之——Uri结构与代码提取

前言:依然没有前言…… 相关博客:1、《Uri详解之——Uri结构与代码提取》2、《Uri详解之二——通过自定义Uri外部启动APP与Notification启动》 上几篇给大家讲了ContentProvider,里面有用到Uri,可能很多同学对Uri是什么,怎么来的,这些都不是很熟悉,今天就给大家具体讲讲Uri 一、URI与Uri 大家可能经常会看到在开发时,怎么有的时候是URI,...

启舰 11万+

Visual Studio Community与Visual Studio Community与VS Code有啥区别

Visual Studio Code提供了基本的代码编辑、调试和版本控制功能,以及丰富的插件和扩展库。Visual Studio Community和Visual Studio Code在功能上有很大的差异,Visual Studio Community提供了比Visual Studio Code更多的功能,包括代码重构、智能提示、图形化设计等。他的优势在于它的轻量级和灵活性。此外,Visual Studio Code还具有丰富的扩展和插件生态系统,用户可以通过安装插件来扩展其功能,从而满足自己的需求。

m0_56551554的博客 2855

QUIC 协议域名封堵:核心原理、关键技术与实现路径(C/C++代码实现)

随着 QUIC 协议在互联网领域的广泛应用,其基于 UDP 的传输特性与加密设计,打破了传统 TCP 协议下的域名封堵逻辑,给网络合规管理与安全防护带来新的技术难题。本文将脱离具体代码实现,聚焦 QUIC 协议域名封堵的核心原理、关键技术环节与实际落地路径,从协议特性本质出发,解析如何在遵循 RFC 9000、RFC 9001 等规范的前提下,实现对 QUIC 流量的精准域名封堵。

chen1415886044的博客 1488

Android中的Uri详解

Uri详解Uri详解1、URI与Uri2、概述3、示例4、代码提取5、ContentUris处理Uri6、uri与file、path相互转化7、常用Uri参考 Uri详解 1、URI与Uri 大家可能经常会看到在开发时,怎么有的时候是URI,有的时候是Uri,这是怎么回事? 名称如此相像的两个类是有什么区别和联系? 1.所属的包不同。URI位置在java.net.URI,显然是Java提供的一个类。而Uri位置在android.net.Uri,是由Android提供的一个类。所以初步可以判断,Uri是URI

JMW1407的博客 1万+

进阶数据结构——链式前向星

链式前向星是一种进阶的数据结构,主要用于图的存储。我希望大家先看这个视频(蓝色字体点进去) 不然你很难理解的。在图论中,图的存储方式主要有邻接矩阵和邻接表两种。邻接矩阵虽然建图简单方便,但占内存较大,节点数量稍微大点的题目就难以使用(适合稠密图);而邻接表虽然节省空间,但其指针形式难写易错,且vector形式的读取速度较慢,易导致大数据下的超时(TLE)。针对上述问题,链式前向星作为一种折中的方式应运而生。链式前向星本质上是一种静态链表,它将数据以链表形式连接在一起。

ycs66的博客 2147

android通过uri得到文件对象,安卓[android] 通过Uri获取File文件

/*** 通过Uri返回File文件* 注意:通过相机的是类似content://media/external/images/media/97596* 通过相册选择的:file:///storage/sdcard0/DCIM/Camera/IMG_20150423_161955.jpg* 通过查询获取实际的地址* @param uri* @return*/public File getFileBy...

weixin_26901145的博客 3290

从零到一:AIC8800 USB-WiFi模块在Linux内核6.x下的驱动适配与避坑指南

本文详细介绍了AIC8800 USB-WiFi模块在Linux内核6.x下的驱动适配全流程,包括环境准备、源码编译、内核API变更处理及常见问题解决方案。重点针对驱动适配中的符号导出、设备ID识别和固件加载等核心挑战提供实用指南,帮助开发者高效完成硬件驱动兼容性调试。

k8l9m0n的博客 1069

HyperLynx(十八)DDR(一)DDR简介和DDR的数据仿真

LVTTL电平为单端信号,而SSTL电平本质上是差分对,其实现机制是将信号与参考电平Vref组成差分对进行比较,如图所示,VIH和VIL各有一个交流参数AC和直流参数DC,信号第一次越过AC门限的时刻,作为时序计算的参考点,此后只要信号保持DC门限内,逻辑状态保持不变,这种设计减小了噪声、振铃等对于信号质量的影响。经过调整后,控制器在发送颗粒1的DQS后,延时1ns再发送颗粒2的DQS,则颗粒1在1ns后收到对齐的DQS和CLK,颗粒2在2ns后收到对齐的DQS和CLK,从而满足了时序关系。

小幽余生不加糖 7700

Android 打开相机、相册获取图片文件,适配支持Android 10.0、Android 9.0系统,解决解决Android 6.0以上的高版本跳转相机闪退问题,以及相机返回图片不显示问题。

解决Android 6.0以上的高版本跳转相机闪退问题,以及相机返回图片不显示问题。 AndroidManifest.xml 中添加权限 <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" pac...

ERP_LXKUN_JAK 1万+

Ubuntu 系统下安装 OpenClaw(原 Clawdbot)的详细指南

Ubuntu 系统下安装 OpenClaw(原 Clawdbot)的详细指南

Science prince的博客 3539

android uri uri,Android中Uri和Path之间的转换

Android Uri,Path与File的相互转换(新)一、path->fileFile file= newFile(path);二、 file->pathString path=file.getPath();注意URI和Uri的区别1URI:是java.net的子类2Uri :是android.net的子类,Uri 不能被实例化三、 URI->FileFile file= n...

weixin_31151281的博客 1097

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

android 定义uri,日常爬坑-android uri 生命周期问题

最近在写我的个人应用KeepassA时,遇到了android文件uri生命周期的问题,被文件真实路径的获取搞得有点懵逼。从android p开始,谷歌对文件访问的权限限制的更加变态了,如果想兼容大多数机型,使用谷歌提供的ASF框架是一个很好的选择。但是该框架只能返回文件的uri,并不能返回文件路径,并且随着android的进一步升级,特别是从android Q 开始,已经完全无法从uri获取到文件...

weixin_32073537的博客 1092

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Android通过相机拍照后无法获取URI问题解决

Android开发中经常会使用相机拍照和从相册获取图片的功能,实现起来比较简单, 打开相册 Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); activity.startActivityForResult(intent, GET_IMAGE...

奋斗小强的博客 3728

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

基于快马AI三分钟搞定安卓FileProvider:智能解析content://URI实战

例如content://com.example.app.provider/files/myfile.txt,其中com.example.app.provider是FileProvider在清单文件中声明的authority,/files/myfile.txt是文件在应用内部存储中的相对路径。这包括AndroidManifest.xml中的provider声明、res/xml/file_paths.xml的路径配置,以及Java/Kotlin中使用FileProvider的示例代码。能大幅简化这个开发过程。

SilvermistRaven28的博客 1万+

android字符串转换成uri,android - Java - 将String转换为有效的URI obj

android - Java - 将String转换为有效的URI obj我试图从String获取一个java.net.URI对象。该字符串有一些字符需要用它们的百分比转义序列替换。 但是当我使用URLEncoder对UTF-8编码的字符串进行编码时,即使/被替换为它们的转义序列。如何从String对象获取有效的编码URL?[http://www.google.com?q=a] b提供htt...

weixin_36364419的博客 2129

java 解析uri_Uri详解之——Uri结构与代码提取

一、URI与Uri大家可能经常会看到在开发时,怎么有的时候是URI,有的时候是Uri,这是怎么回事?名称如此相像的两个类是有什么区别和联系?1.所属的包不同。URI位置在java.net.URI,显然是Java提供的一个类。而Uri位置在android.net.Uri,是由Android提供的一个类。所以初步可以判断,Uri是URI的“扩展”以适应Android系统的需要。2.作用的不同。URI类...

weixin_29668721的博客 4676

安卓7.0系统以上Uri访问抛出FileUriExposedException

安卓项目中很多地方用到了相册获取、apk安装、本地文件打开等,但是在高版本(7.0以上)就会抛异常,因为需要我们单独进行处理 一、原因 从Android 7.0开始,不再允许在app中把file:// Uri暴露给其他app,否则应用会抛出FileUriExposedException。原因在于,Google认为使用file:// Uri存在一定的风险。 二、解决方法 使用FileProvid...

qq_36356379的博客 337
上一篇: Android中执行shell命令
下一篇: ViewModel的使用-ViewModel与RecycleView(七)
Mr_Tony
博客等级 码龄13年 348粉丝 417原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值