English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

توضيح كيفية الوصول إلى التخزين الخارجي في Android 4.4 ومثال على الشيفرة

Android4.4 Access external storage

In the Android 4.4 system, the external storage card (SD card) is called a secondary external storage device (secondary storage), and applications can no longer write data to the external storage card (SD card). The WRITE_EXTERNAL_STORAGE permission is only granted write permissions to the main external storage (primary storage) on the device, and for other external storage, the file attributes are all changed to be based on the folder structure. Applications do not need to obtain the WRITE_EXTERNAL_STORAGE permission, but can manage folders related to their package names. For example, if the package name of the application is com.example.externalstorage, then the Android/data/com.example.externalstorage/ folder on the external storage is its own, can be accessed at will, and does not require permissions. In addition, it should be especially noted that when the application is uninstalled, the corresponding folders and data created on the SD card will be completely deleted at the same time.

Exceptionally, in Android 4.4, system applications (referring to applications with platform signature, or pre-installed in the /system/priv-app directory) can obtain full read and write permissions to SD cards by using the WRITE_MEDIA_STORAGE permission.

Android 4.4 adds the following function to access external storage:

 getExternalFilesDirs(null), returns multiple sd cards private data area files directory for the application

/storage/sdcard0/Android/data/<package_name>/files

/storage/sdcard1/Android/data/<package_name>/files

getExternalCacheDirs(), returns multiple sd card private database cache directories for the application

/storage/sdcard0/Android/data/<اسم الحزمة>/caches

/storage/sdcard1/Android/data/<اسم الحزمة>/caches

Context.getObbDirs(), يعود بملفات البيانات الخاصة في مجلدات obb تحت بطاقات SD المختلفة (عادةً مجلد بيانات اللعبة).

/storage/sdcard0/Android/obb/<اسم الحزمة>

/storage/sdcard1/Android/obb/<اسم الحزمة>

يمكنني الحصول على مسار بطاقة SD بشكل صحيح باستخدام الدالة أعلاه في نظامي Android 5.1، ولكن يمكن رؤية مسار التخزين الداخلي فقط في نظام Android 4.4.

 
   
 

حسب المعلومات المتاحة على الإنترنت، يمكن إدارة بطاقة SD بعد Android 4.4 عن طريق تعديل ملفات النظام، مثل ما يلي:

1<permission name="android.permission.WRITE_EXTERNAL_STORAGE" >
2     <group gid="sdcard_r" />
3     <group gid="sdcard_rw" />
4     <group gid="media_rw" />
5   </permission>

تعديل ملف /system/etc/permissions/platform.xml بنقطة android.permission.WRITE_EXTERNAL_STORAGE، أضف <group gid="media_rw" /> (يتطلب صلاحيات root).

بعد التعديل، يمكنك التحكم في بطاقة SD بسهولة.

شكرًا على القراءة، آمل أن تكون مفيدًا للجميع، شكرًا لدعمكم لموقعنا!

من المحتمل أن تفضّل