Einzelnen Beitrag anzeigen

bra

Registriert seit: 20. Jan 2015
711 Beiträge
 
Delphi 10.2 Tokyo Enterprise
 
#5

AW: [Android] angeschlossene "/storage/"s finden

  Alt 9. Aug 2016, 09:55
Wir verwenden folgende Routine, schau mal, ob die bei dir das richtige liefert - würde mich nämlich auch interessieren :

Delphi-Quellcode:
function GetSdCardPath: JFile;
var
  i, nSDK_Level: Integer;
  jfMntPath: JFile;
  jfList: TJavaObjectArray<JFile>;
  sMediaMounted, sPathStorageState: string;
begin
  Result := nil;
  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 begin
          Result := jfList.Items[i];
          Break;
        end;
      end;
    end;
  end;
end;
  Mit Zitat antworten Zitat