參照安卓官網: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
懂的同學說說,這兩個報錯是怎么回事?
謝謝高手指點!大家周末愉快!
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/284842.html
標籤:Android
上一篇:企業為什么要有自己的APP
