Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Write access to an External Storage Directory


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Jul 17, 2017 5:17 AM Last Post By: Amiga Schröder
Amiga Schröder

Posts: 3
Registered: 8/11/09
Write access to an External Storage Directory  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 14, 2017 8:05 AM
Hello,

my app should write files on an external sd card.
I've set the authorization "write/read access to external storag" in the project settings.
But since Android 5 it isn't possible to write to the external storage. The app must ask the user to grant write access.

Here you can find the information how it has to work:
https://metactrl.com/docs/sdcard-on-lollipop/

Under
https://developer.android.com/training/articles/scoped-directory-access.html and
https://developer.android.com/training/permissions/requesting.html I've found some explanations for Android.

But my problem is: how can I implement this functionality in Delphi?

Best regards
Heiko
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: Write access to an External Storage Directory  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 14, 2017 6:22 PM   in response to: Amiga Schröder in response to: Amiga Schröder
Amiga Schröder wrote:

my app should write files on an external sd card.
I've set the authorization "write/read access to external storag" in the project settings.
But since Android 5 it isn't possible to write to the external storage. The app must ask the user to grant write
access.

Here you can find the information how it has to work:
https://metactrl.com/docs/sdcard-on-lollipop/

Under
https://developer.android.com/training/articles/scoped-directory-access.html and

This article refers to Android 7.

https://developer.android.com/training/permissions/requesting.html I've found some explanations for Android.

But my problem is: how can I implement this functionality in Delphi?

You should not need to implement requesting permissions as per this link, unless you must have targetSdkVersion of 23
or higher (Delphi sets a value of 14).

Please describe your actual problem, and provide a code example if possible.

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Amiga Schröder

Posts: 3
Registered: 8/11/09
Re: Write access to an External Storage Directory  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 17, 2017 5:17 AM   in response to: Dave Nottage in response to: Dave Nottage
Hello,

many thanks for your fast response...

You should not need to implement requesting permissions as per this link, unless you must have targetSdkVersion of 23
or higher (Delphi sets a value of 14).

I've changed it, but it doesn't work.
This is my simple Manifest file:

<?xml version="1.0" encoding="utf-8" ?> 
<!--  BEGIN_INCLUDE(manifest)   --> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.embarcadero.renfile" android:versionCode="1" android:versionName="1.0.0" android:installLocation="preferExternal">
<!--  This is the platform API where NativeActivity was introduced.   --> 
  <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" /> 
  <uses-permission android:name="android.permission.INTERNET" /> 
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> 
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
  <uses-feature android:glEsVersion="0x00020000" android:required="True" /> 
  <application android:persistent="False" android:restoreAnyVersion="False" android:label="renfile" android:debuggable="True" android:largeHeap="False" android:icon="@drawable/ic_launcher" android:theme="@style/AppTheme" android:hardwareAccelerated="true">
 <!-- 
 Our activity is a subclass of the built-in NativeActivity framework class.
             This will take care of integrating with our NDK code. 
 
  --> 
 <activity android:name="com.embarcadero.firemonkey.FMXNativeActivity" android:label="renfile" android:configChanges="orientation|keyboard|keyboardHidden|screenSize" android:launchMode="singleTask">
<!--  Tell NativeActivity the name of our .so   --> 
          <meta-data android:name="android.app.lib_name" android:value="renfile" /> 
          <intent-filter>
            <action android:name="android.intent.action.MAIN" /> 
            <category android:name="android.intent.category.LAUNCHER" /> 
          </intent-filter>
          </activity>
          <receiver android:name="com.embarcadero.rtl.notifications.NotificationAlarm" /> 
  </application>
  </manifest>
 <!--  END_INCLUDE(manifest)  --> 

Please describe your actual problem, and provide a code example if possible.

This is the simple example of my app:

procedure TForm1.Button4Click(Sender: TObject);
const
  cFileOld = '/storage/3538-6162/Download/testfile.txt';
  cFileNew = '/storage/3538-6162/Download/testfile.bak';
begin
  if not FileExists(cFileOld) then
  begin
    showmessage('file doesn''t exist');
    exit;
  end;
  If RenameFile(cFileOld, cFileNew) then
     showmessage('renamed')
  else
     showmessage('failed')
end;


The result of this code is: failed

The system has Android 6.0.1 installed.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02