Re: FYI: How to reliably identify an Android Tablet microSD Card

2018-12-20 Thread Bob Sneidar via use-livecode
Interesting approach. Of course, the downside is that if anything changes, the 
method becomes ineffective for that new device or for all andriods if the 
change is fundamental enough. 

Bob S


> On Dec 19, 2018, at 03:37 , Peter Reid via use-livecode 
>  wrote:
> 
> FYI
> 
> I've managed to put together some code that reliably locates the microSD card 
> in 4 very different Android-based tablets. The approach involves 3 different 
> methods:
> 
> 1. Search for a known folder on the SD card starting in the standard "/mnt" 
> folder using a breadth-first search strategy.
> 
> 2. Search for a known folder on the SD card starting in the less standard 
> "/storage" folder using a breadth-first search strategy.
> 
> 3. Search for a known folder using full paths that are used by specific 
> manufacturers. These look as though they should be located by method 1. (they 
> are all paths from "/mnt") but sometimes fail 1. however they work if the 
> full path is specified!
> 
> Here's my code for "findSDcard"...
> 
> 
> 
> on findSDcard
>   constant \
>  cSDcardRoot1 = "/mnt/ext_sdcard/Android/data/com.myorg.myapp/files", \
>  cSDcardRoot2 = "/mnt/sdcard2/Android/data/com.myorg.myapp/files", \
>  cSDcardRoot3 = "/mnt/m_external_sd/Android/data/com.myorg.myapp/files", \
>  cSDcardRoot4 = "/mnt/sdcard/Android/data/com.myorg.myapp/files", \
>  cSDcardRoot5 = "/mnt/extSdCard/Android/data/com.myorg.myapp/files", \
>  cSDcardRoot6 = "/mnt/external_sd/Android/data/com.myorg.myapp/files", \
>  cSDcardRoot7 = "/mnt/SDCard/Android/data/com.myorg.myapp/files"
> 
>global gDataPath -- /myapp-data
>global gSDcard -- path to app's data folder
> 
>   set wholeMatches to true
>   put empty into gSDcard
>   put (char 2 to -1 of gDataPath) into tTargetFolderName
>   if the platform is "android" then
>  put "/mnt" into tDeviceRoot
>  if there is a folder tDeviceRoot then
> -- search in standard /mnt folders:
> put empty into tFoundPath
> folderExists tTargetFolderName, tDeviceRoot, tFoundPath
> if tFoundPath is not empty then
>put tFoundPath into gSDcard
> end if
>  end if
>  if gSDcard is empty then
> -- try non-standard /storage folders:
> if there is a folder "/storage" then
>-- search in non-standard /storage folders:
>put "/storage" into tDeviceRoot
>put empty into tFoundPath
>folderExists tTargetFolderName, tDeviceRoot, tFoundPath
>if tFoundPath is not empty then
>   put tFoundPath into gSDcard 
>end if
> end if
>  end if
>  if gSDcard is empty then
> -- try bespoke SD locations:
> if there is a folder cSDcardRoot1 then
>put cSDcardRoot1 into gSDcard-- Huawei
> else if there is a folder cSDcardRoot2 then
>put cSDcardRoot2 into gSDcard-- Amazon
> else if there is a folder cSDcardRoot3 then
>put cSDcardRoot3 into gSDcard-- Lenovo
> else if there is a folder cSDcardRoot4 then
>put cSDcardRoot4 into gSDcard-- Fusion
> else if there is a folder cSDcardRoot5 then
>put cSDcardRoot5 into gSDcard-- ??
> else if there is a folder cSDcardRoot6 then
>put cSDcardRoot6 into gSDcard-- ??
> else if there is a folder cSDcardRoot7 then
>put cSDcardRoot7 into gSDcard-- Hudl?
> end if
>  end if
>   end if
> end findSDcard
> 
> on folderExists pFolderName, pRootPath, @pFoundPath
>   constant cNoDotsRegex = "^\..*"
> 
>   -- breadth-first search for a given folder
>   put empty into pPath
>   if there is a folder pRootPath then
>  put empty into tSubFolders
>  put folders(pRootPath) into tFolderList
>  filter lines of tFolderList without regex cNoDotsRegex
>  repeat for each line tFolder in tFolderList
> if tFolder = pFolderName then
>-- found it:
>put pRootPath into pFoundPath
>exit folderExists
> else
>-- add sub-folder to list for checking:
>put pRootPath & "/" & tFolder & return after tSubFolders
> end if
>  end repeat
>  if tSubFolders is empty then
> exit folderExists
>  end if
>  repeat for each line tSubFolder in tSubFolders
> folderExists pFolderName, tSubFolder, pFoundPath
> if pFoundPath is not empty then
>exit folderExists
> end if
>  end repeat
>   end if
> end folderExists
> 
> 
> 
> Note that the above was necessary because specialFolderPath("external 
> documents") doesn't work reliably across the 4 Android-based tablets I'm 
> trying to support.
> 
> If anyone has a more elegant or succinct method, please let me know.  In the 
> meantime you're welcome to use the above code.
> 
> Peter
> --
> Peter Reid
> Loughborough, UK
> 
>> On 28 Nov 201

FYI: How to reliably identify an Android Tablet microSD Card

2018-12-19 Thread Peter Reid via use-livecode
FYI

I've managed to put together some code that reliably locates the microSD card 
in 4 very different Android-based tablets. The approach involves 3 different 
methods:

1. Search for a known folder on the SD card starting in the standard "/mnt" 
folder using a breadth-first search strategy.

2. Search for a known folder on the SD card starting in the less standard 
"/storage" folder using a breadth-first search strategy.

3. Search for a known folder using full paths that are used by specific 
manufacturers. These look as though they should be located by method 1. (they 
are all paths from "/mnt") but sometimes fail 1. however they work if the full 
path is specified!

Here's my code for "findSDcard"...



on findSDcard
   constant \
  cSDcardRoot1 = "/mnt/ext_sdcard/Android/data/com.myorg.myapp/files", \
  cSDcardRoot2 = "/mnt/sdcard2/Android/data/com.myorg.myapp/files", \
  cSDcardRoot3 = "/mnt/m_external_sd/Android/data/com.myorg.myapp/files", \
  cSDcardRoot4 = "/mnt/sdcard/Android/data/com.myorg.myapp/files", \
  cSDcardRoot5 = "/mnt/extSdCard/Android/data/com.myorg.myapp/files", \
  cSDcardRoot6 = "/mnt/external_sd/Android/data/com.myorg.myapp/files", \
  cSDcardRoot7 = "/mnt/SDCard/Android/data/com.myorg.myapp/files"
  
global gDataPath -- /myapp-data
global gSDcard -- path to app's data folder

   set wholeMatches to true
   put empty into gSDcard
   put (char 2 to -1 of gDataPath) into tTargetFolderName
   if the platform is "android" then
  put "/mnt" into tDeviceRoot
  if there is a folder tDeviceRoot then
 -- search in standard /mnt folders:
 put empty into tFoundPath
 folderExists tTargetFolderName, tDeviceRoot, tFoundPath
 if tFoundPath is not empty then
put tFoundPath into gSDcard
 end if
  end if
  if gSDcard is empty then
 -- try non-standard /storage folders:
 if there is a folder "/storage" then
-- search in non-standard /storage folders:
put "/storage" into tDeviceRoot
put empty into tFoundPath
folderExists tTargetFolderName, tDeviceRoot, tFoundPath
if tFoundPath is not empty then
   put tFoundPath into gSDcard 
end if
 end if
  end if
  if gSDcard is empty then
 -- try bespoke SD locations:
 if there is a folder cSDcardRoot1 then
put cSDcardRoot1 into gSDcard-- Huawei
 else if there is a folder cSDcardRoot2 then
put cSDcardRoot2 into gSDcard-- Amazon
 else if there is a folder cSDcardRoot3 then
put cSDcardRoot3 into gSDcard-- Lenovo
 else if there is a folder cSDcardRoot4 then
put cSDcardRoot4 into gSDcard-- Fusion
 else if there is a folder cSDcardRoot5 then
put cSDcardRoot5 into gSDcard-- ??
 else if there is a folder cSDcardRoot6 then
put cSDcardRoot6 into gSDcard-- ??
 else if there is a folder cSDcardRoot7 then
put cSDcardRoot7 into gSDcard-- Hudl?
 end if
  end if
   end if
end findSDcard

on folderExists pFolderName, pRootPath, @pFoundPath
   constant cNoDotsRegex = "^\..*"
   
   -- breadth-first search for a given folder
   put empty into pPath
   if there is a folder pRootPath then
  put empty into tSubFolders
  put folders(pRootPath) into tFolderList
  filter lines of tFolderList without regex cNoDotsRegex
  repeat for each line tFolder in tFolderList
 if tFolder = pFolderName then
-- found it:
put pRootPath into pFoundPath
exit folderExists
 else
-- add sub-folder to list for checking:
put pRootPath & "/" & tFolder & return after tSubFolders
 end if
  end repeat
  if tSubFolders is empty then
 exit folderExists
  end if
  repeat for each line tSubFolder in tSubFolders
 folderExists pFolderName, tSubFolder, pFoundPath
 if pFoundPath is not empty then
exit folderExists
 end if
  end repeat
   end if
end folderExists



Note that the above was necessary because specialFolderPath("external 
documents") doesn't work reliably across the 4 Android-based tablets I'm trying 
to support.

If anyone has a more elegant or succinct method, please let me know.  In the 
meantime you're welcome to use the above code.

Peter
--
Peter Reid
Loughborough, UK

> On 28 Nov 2018, at 11:49am, Peter Reid  wrote:
> 
> I've got an app running on an Android 8.1 7in tablet which uses a microSD 
> card for its RW data storage. I've tried using:
> 
>   specialFolderPath("external documents")
> 
> which the docs describe as follows:
> 
>   • "external documents": The folder on the primary shared/external 
> storage device where application-specific data can be placed
> but this doesn't point to the