学习安卓官网 FileProvider 分享文件,遇到的几点问题,请教同学!
参照安卓官网:https://developer.android.google.cn/reference/androidx/core/content/FileProvider
在Android Studio中写了一个简单的app,却遭遇到如下的一系列问题,请教大家。
1. 这个简单app,只有一个activity,类似HelloWorld, 只是加了一个button的 click处理而已。
编译生成apk时,提示如下的警告:
MainActivity.java使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
请问,具体该如何找到,是使用了哪个API引起的呢?
2. App参照官网文档,
1). file_paths.xml 中定义如下。
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="my_images" path="images/"/>
</paths>
文档说 "files-path" represents files in the files/ subdirectory of your app's internal storage area. This subdirectory is the same as the value returned by Context.getFilesDir().
假设app的package id是com.mydomain.myapp,那么这个images 文件夹,在安卓手机上实际的物理路径,是
设备存储的/data/data/com.mydomain.myapp/files/images吗?
这个文件夹,用手机上的“文件管理”查看不到;用Android Studio里的Device File Explorer才能看到?
2). 上述xml文件中,类似files-path,可以用external-path represents files in the root of the external storage area,代表SD存储;那么,用什么代表设备存储的根目录(root of the internal storage area)呢?
3). 官网文档中代码如下。
File imagePath = new File(Context.getFilesDir(), "images");
File newFile = new File(imagePath, "default_image.jpg");
Uri contentUri = getUriForFile(getContext(), "com.mydomain.fileprovider", newFile);
俺将上述三行代码,放在button的onClick()中,编译时却报错:
第一行报错:错误: 无法从静态上下文中引用非静态 方法 getFilesDir()
第三行报错:错误: 不兼容的类型: AccessControlContext无法转换为Context
懂的同学说说,这两个报错是怎么回事?
谢谢高手指点!大家周末愉快!
在Android Studio中写了一个简单的app,却遭遇到如下的一系列问题,请教大家。

1. 这个简单app,只有一个activity,类似HelloWorld, 只是加了一个button的 click处理而已。
编译生成apk时,提示如下的警告:
MainActivity.java使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。
请问,具体该如何找到,是使用了哪个API引起的呢?
2. App参照官网文档,
1). file_paths.xml 中定义如下。
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="my_images" path="images/"/>
</paths>
文档说 "files-path" represents files in the files/ subdirectory of your app's internal storage area. This subdirectory is the same as the value returned by Context.getFilesDir().
假设app的package id是com.mydomain.myapp,那么这个images 文件夹,在安卓手机上实际的物理路径,是
设备存储的/data/data/com.mydomain.myapp/files/images吗?
这个文件夹,用手机上的“文件管理”查看不到;用Android Studio里的Device File Explorer才能看到?
2). 上述xml文件中,类似files-path,可以用external-path represents files in the root of the external storage area,代表SD存储;那么,用什么代表设备存储的根目录(root of the internal storage area)呢?
3). 官网文档中代码如下。
File imagePath = new File(Context.getFilesDir(), "images");
File newFile = new File(imagePath, "default_image.jpg");
Uri contentUri = getUriForFile(getContext(), "com.mydomain.fileprovider", newFile);
俺将上述三行代码,放在button的onClick()中,编译时却报错:
第一行报错:错误: 无法从静态上下文中引用非静态 方法 getFilesDir()
第三行报错:错误: 不兼容的类型: AccessControlContext无法转换为Context
懂的同学说说,这两个报错是怎么回事?
谢谢高手指点!大家周末愉快!
...全文
相关推荐
基于Android FileProvider 属性配置详解及FileProvider多节点问题
主要介绍了基于Android FileProvider 属性配置详解及FileProvider多节点问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
FileProvider
FileProvider的使用
内涵FileProvider的android-support-v4包,版本在安卓5.0 sdk
资源不能选择0分下载了吗?可怕。这是内涵FileProvider的android-support-v4包,版本在安卓5.0 sdk 内。
解决安卓7.0拍照闪退的问题,安卓拍照,图片选择,剪切,使用fileprovider7.0文件读写的权限,安卓6.0以上权限适配
安卓拍照,图片选择,剪切,解决安卓7.0拍照闪退的问题,使用fileprovider适配权限,并获取对应uri,安卓7.0和安卓7.0之前两种实现的对比,权限请求,外送一个FileUtil的文件工具类
Android-一行代码完成Android8FileProvider适配~
一行代码完成Android 8 FileProvider适配~


