如何在Android 6存储访问的变化? [英] How does storage access change on Android 6?

查看:507
本文介绍了如何在Android 6存储访问的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

安卓有很多的变化,如何处理SD卡和存储一般的:

  • 在API 3 - 你得到所有访问,没有所需的权限
  • 在API 4-15 - 你需要使用WRITE_EXTERNAL_STORAG​​E,你会得到所有访问
  • 在API 16-18 - 如果你想为只读,使用READ_EXTERNAL_STORAG​​E
  • 在API 19-20 - 您无法读取或写入到辅助外部存储(SD卡),除非你的应用程序是一个系统的应用程序,或者你有root
  • 在API 21-22 - 以访问SD卡,你需要问权限的用户,并使用文件API的DocumentFile API来代替。这raied了很多问题,因为我已经写 此处 ,的 这里 < STRONG>此处

使用API​​ 23(安卓6)开始,事情似乎又再次改变...

问题

有关API 23日,至少有两件事情是新的,是与存储相关的:

由于是具有SD卡,并且由于仿真器本身并没有真正有使用SD卡的功能,它仍然不可能知道发生了什么事情。没有一款Android 6的设备在那里

的问题

  1. 使用文件API,而不是DocumentFile将SD卡获得访问权限?

  2. 如果我想获得所有外部存储路径(包括SD卡),这是否意味着我需要两次请求此权限:一个是主要外部存储和一个用于SD卡

  3. 在手册发放许可之前在SD卡上以任何方式访问的文件?

  4. 假设已经选择使用可采用的存储设备的用户,这是什么意思为检索应用程序的文件的路径的各种功能?例如:getFilesDir,getExternalFilesDir,...?请问getExternalFilesDirs的奥德改变因为什么呢?

  5. 发生当用户从/移动应用程序到SD卡(使用可采用的存储设备)的应用程序的文件是什么?那么在SD卡上的应用程序的文件吗?他们会留下来吗?还是会动的地方?

    例如,如果应用程序具有SD卡上的file1.txt的,在路径/存储/ extSdCard /机器人/数据/ appPackageName,它具有一个文件FILE2.TXT(或连关于路径的主要外部存储相同的名称)/存储/模拟/ 0 /安卓/数据/ appPackageName。切换后,会发生什么,这些文件?他们将如何合并成一个单一的文件夹,如果在所有?

  6. 在移动应用程序到SD卡(使用可采用的存储设备),这是否意味着没有内部存储空间将被使用?

解决方案

我来回答可采用的存储设备相关的问题:

  <醇开始=4>   
  • 在假设已经选择使用可采用的存储设备的用户,这是什么意思为检索的路径的各种功能   该应用程序的文件吗?例如:getFilesDir,getExternalFilesDir,...?   请问getExternalFilesDirs的奥德改变因为什么呢?
  •   

    当用户选择使用SD卡作为可采用的存储设备(格式为内部),现在意味着SD卡仅作为内部存储即没有SD卡可用来存储下载的文件。将有由相关的方法返回的路径没有秩序的变化。例如:getExternalFilesDir()将只列出外部存储路径,如果用户格式化自己的SD卡作为可采用的存储设备。 SD卡路径将无法使用。

         
  • 发生当用户从/移动应用程序到SD卡(使用可采用的存储设备)的应用程序的文件是什么?什么   关于SD卡上的应用程序的文件吗?他们会留下来吗?还是会   移动的地方?例如,如果该应用对file1.txt的   SD卡,在路径/存储/ extSdCard /安卓/数据/ appPackageName,并   其对主文件FILE2.TXT(或者甚至相同的名称)   在路径上的外部存储   /存储/模拟/ 0 /安卓/数据/ appPackageName。切换后,   会发生什么,这些文件?他们将如何合并成一个单一的   文件夹,如果在所有?
  •   

    在以往的用户会选择他的SD卡作为可采用的存储设备,那么用户需要自己的SD卡作为内部存储使用的格式化为内部的选项格式化。格式是指存储在SD卡将被删除所有数据/文件。同样,当用户想从可采用的存储设备删除了SD卡,然后用户再有他的SD卡作为移动存储使用格式为:格式便携式选项。

      <醇开始=6>   
  • 当移动应用程序到SD卡(使用可采用的存储设备),这是否意味着没有内部存储空间将被使用?
  •   

    是的,原来的内部存储空间将不会被使用。因为选择SD卡作为可采用的存储设备后,只有SD卡存储将被使用。所有数据/高速缓存将被存储到SD卡

    Background

    Android had a lot of changes as to how to handle the SD-card and storage in general:

    Starting with API 23 (Android 6), things seem to change yet again...

    The problem

    For API 23, there are at least 2 things that are new and are storage-related :

    • "Adoptable Storage Devices" - The user can optionally make the SD-card as something that's like the primary external storage.
    • As part of the new permissions mechanism (requesting permissions at runtime), it seems that storage is also a permission the user needs to confirm. This is for both READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE

    Since there is no Android 6 device out there that has SD-card, and because the emulator itself doesn't really have the ability to use an SD-card, it's still impossible to know what's going on.

    The questions

    1. Will the SD-card get the access using the File-API instead of DocumentFile?

    2. If I want access to all external storage paths (including SD-card), does this mean I need to request this permissions twice: one for the primary external storage and one for the SD-card?

    3. Are files on the SD-card accessible in any way before the manual granting of the permission?

    4. Suppose the user has chosen to use "Adoptable Storage Devices", what does it mean for the various functions that retrieve the paths of the app's files? For example : getFilesDir, getExternalFilesDir,... ? Would the oder of getExternalFilesDirs change because of it?

    5. What happens to the files of the app when the user moves the app from/to the SD-card (using the "Adoptable Storage Devices") ? What about the app's files on the SD-card? Would they stay? Or would they move somewhere?

      For example, if the app has "file1.txt" on the SD-card, on path "/storage/extSdCard/Android/data/appPackageName", and it has a file "file2.txt" (or even the same name) on the primary external storage on path "/storage/emulated/0/Android/data/appPackageName". After switching, what would happen for those files? How would they merge into a single folder, if at all?

    6. When moving the app to the SD-card (using "Adoptable Storage Devices"), does it mean no internal storage will be used?

    解决方案

    Let me answer "Adoptable Storage Devices" related questions:

    1. Suppose the user has chosen to use "Adoptable Storage Devices", what does it mean for the various functions that retrieve the paths of the app's files? For example : getFilesDir, getExternalFilesDir,... ? Would the oder of getExternalFilesDirs change because of it?

    When user choose to use SD card as "Adoptable Storage Device" (Format as internal), it means now that SD card is available only as Internal Storage i.e. no SD card available to store downloaded files. There will be no order change in paths returned by the related methods. For example: getExternalFilesDir() will list only external storage path if user formatted his SD card as "Adoptable Storage Devices". SD card path will not be available.

    1. What happens to the files of the app when the user moves the app from/to the SD-card (using the "Adoptable Storage Devices") ? What about the app's files on the SD-card? Would they stay? Or would they move somewhere? For example, if the app has "file1.txt" on the SD-card, on path "/storage/extSdCard/Android/data/appPackageName", and it has a file "file2.txt" (or even the same name) on the primary external storage on path "/storage/emulated/0/Android/data/appPackageName". After switching, what would happen for those files? How would they merge into a single folder, if at all?

    When ever user will choose his SD card as "Adoptable Storage Devices" then user need to format his SD card as internal storage using "Format as internal" option. Format means all the data/files stored on SD card will be erased. Similarly when user want to remove his SD card from "Adoptable Storage Devices" then user again have to format his SD card as portable storage using "Format as portable" option.

    1. When moving the app to the SD-card (using "Adoptable Storage Devices"), does it mean no internal storage will be used?

    Yes, original internal storage will not be used. Only SD card storage will be used because after choosing SD card as "Adoptable Storage Devices". All the data/cache will be stored to SD card

    这篇关于如何在Android 6存储访问的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆