参照安卓官网: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
懂的同学说说,这两个报错是怎么回事?
谢谢高手指点!大家周末愉快!