File: mergeall-android-scripts/_readme-items/PYDROID3-TKINTER/CODE/_permissions.py

#==========================================================================
# Test reads and writes at root and in app-specific subfolders of both 
# internal storage (/sdcard) and removable SD card (/storage/xxxx-xxxx).
#
# This assumes the running app has already requested storage permissions
# (e.g., Termux command, Pydroid 3 popup on access, or QPython3 install).
#
# Termux and Pydroid 3 have same access: reads work everywhere; writes 
# work anywhere in internal storage, but only in app's folder on SD card.
# See the docs (or ..) for screenshots of the results in each app.
#
# Put cross-app items on /sdcard (e.g., an /sdcard/work working folder),
# and be careful to retain data in app-specific folders on app uninstall.
#==========================================================================

import os

paths = [
    # internal storage
    '/sdcard',
    '/sdcard/Android/data/ru.iiec.pydroid3',
    '/sdcard/Android/data/com.termux',
    
    # removable sd card
    '/storage/5C32-5336',
    '/storage/5C32-5336/Android/data/ru.iiec.pydroid3',
    '/storage/5C32-5336/Android/data/com.termux'] 

print('\nREADS')
for path in paths:
    assert os.path.exists(path+'/rtest.txt'), path
    try:
        open(path+'/rtest.txt', 'r').read()
        print('worked:', path)
    except:
        print('failed:', path)
        
print('\nWRITES')
for path in paths:
    assert os.path.exists(path), path
    try:
        open(path+'/wtest.txt', 'w').write('1234')
        print('worked:', path)
    except:
        print('failed:', path)
	



[Home page] Books Code Blog Python Author Train Find ©M.Lutz