procedure searchForExternalDevice(deviceNr: byte);
var possibleList: TStringPairList;
searchForDir:
String;
i: Integer;
dirExists: Boolean;
dirList: TStringDynArray;
begin
possibleList:=TStringPairList.create(True);
if (TOSVersion.Major<11)
then
TFileUtils.listSDUSB();
try
dirList:=TDirectory.GetDirectories('
/storage', TSearchOption.soTopDirectoryOnly,
nil);
for i:=0
to length(dirList) - 1
do
begin
if (MatchesMask(dirList[i], '
/storage/????-????'))
then
begin
possibleList.add(TStringPair.create(dirList[i] + '
/Android/data/', '
com.icTrainer/files/'));
possibleList.add(TStringPair.create(dirList[i] + '
/icTrainer/', '
'));
end;
end;
except
on E:
Exception do
log.d('
Can´t access /storage: ' + E.
message);
end;
try
dirList:=TDirectory.GetDirectories('
/mnt/media_rw', TSearchOption.soTopDirectoryOnly,
nil);
for i:=0
to length(dirList) - 1
do
begin
if (MatchesMask(dirList[i], '
/mnt/media_rw/????-????'))
then
possibleList.add(TStringPair.create(dirList[i] + '
/icTrainer/', '
'));
end;
except
on E:
Exception do
log.d('
Can´t access /mnt/media_rw: ' + E.
message);
end;
possibleList.add(TStringPair.create('
/storage/sdcard1/Android/data/', '
AppName/files/'));
possibleList.add(TStringPair.create('
/storage/usbotg/AppName/', '
'));
possibleList.add(TStringPair.create('
/storage/sdcard1/AppName/', '
'));
possibleList.add(TStringPair.create('
/storage/usbdisk/AppName/', '
'));
possibleList.add(TStringPair.create('
/mnt/media_rw/AppName/', '
'));
for i:=0
to possibleList.count - 1
do
begin
searchForDir:=possibleList[i].val1 + possibleList[i].val2;
if ((externalDevice1 = searchForDir)
or (externalDevice2 = searchForDir))
then
continue;
dirExists:=DirectoryExists(possibleList[i].val1);
log.d('
Search for ' + possibleList[i].val1 + '
' + TStringUtils.BoolToStr(dirExists));
if (dirExists)
then
begin
//und hier mache ich jetzt was mit dem Pfad
exit;
end;
end;
end;
class procedure TFileUtils.listSDUSB();
begin
jfMntPath := TJFile.JavaClass.init( StringToJString( '
/storage' ) );
if jfMntPath.isDirectory
and jfMntPath.exists
then begin
nSDK_Level := TJBuild_VERSION.JavaClass.SDK_INT;
if nSDK_Level >= 19
then
begin
sMediaMounted := JStringToString( TJEnvironment.JavaClass.MEDIA_MOUNTED );
jfList := jfMntPath.listFiles;
for i := 0
to jfList.Length-1
do
begin
// getStorageState is added in API level 19; deprecated in API level 21, which introduces getExternalStorageState(File). Delphi interface does not supports this method with parameter.
sPathStorageState := JStringToString( TJEnvironment.JavaClass.getStorageState( jfList.Items[i] ) );
if SameText( sPathStorageState, sMediaMounted )
then
mlog.info('
External(1)(1): '+JStringToString(jfList.Items[i].getPath))
else
mlog.info('
External(1)(2): '+JStringToString(jfList.Items[i].getPath));
end;
end;
end;
mlog.info('
External(2): '+JStringToString(TJEnvironment.JavaClass.getExternalStorageDirectory.getPath));
end;