AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Android SD-Kartenzugriff

Ein Thema von sko1 · begonnen am 25. Mai 2018 · letzter Beitrag vom 26. Mai 2018
Antwort Antwort
Seite 2 von 2     12
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#11

AW: Android SD-Kartenzugriff

  Alt 26. Mai 2018, 09:26
Das gehört zu meinem Helper Functions Link.
Zitat:
Apparently the most robust way to get access to the external storage location is through these two functions GetSysSecondaryStorage and GetSysExternalStorage.
Hier ist eine Diskussion über Permissions.
Hier in der DP gibts auch Infos zu diesem Thema!

Saving data to a file in your Android application geht da anders vor.

Zum Schreiben:
Delphi-Quellcode:
try {
  // Creates a file in the primary external storage space of the
  // current application.
  // If the file does not exists, it is created.
  File testFile = new File(this.getExternalFilesDir(null), "TestFile.txt");
  if (!testFile.exists())
      testFile.createNewFile();

  // Adds a line to the file
  BufferedWriter writer = new BufferedWriter(new FileWriter(testFile, true /*append*/));
  writer.write("This is a test file.");
  writer.close();
  // Refresh the data so it can seen when the device is plugged in a
  // computer. You may have to unplug and replug the device to see the
  // latest changes. This is not necessary if the user should not modify
  // the files.
  MediaScannerConnection.scanFile(this,
                                   new String[]{testFile.toString()}
,
                                   null,
                                   null);
} catch (IOException e) {
  Log.e("ReadWriteFile", "Unable to write to the TestFile.txt file.");
}
zum Lesen:
Delphi-Quellcode:
String textFromFile = "";
// Gets the file from the primary external storage space of the
// current application.
File testFile = new File(this.getExternalFilesDir(null), "TestFile.txt");
if (testFile != null) {
  StringBuilder stringBuilder = new StringBuilder();
  // Reads the data from the file
  BufferedReader reader = null;
  try {
      reader = new BufferedReader(new FileReader(testFile));
      String line;

      while ((line = reader.readLine()) != null) {
        textFromFile += line.toString();
        textFromFile += "\n";
      }

      reader.close();
   } catch (Exception e) {
      Log.e("ReadWriteFile", "Unable to read the TestFile.txt file.");
   }

}
Source Code Link davon


Klappt es damit?
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:40 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz