Android 11: saving a file to the selected folder - storage

In my app I use ActivityResultContracts.OpenDocumentTree() to let the user select a folder in the device storage and allow access to it.
However, on Android 11, if I try to save a file on the selected folder, I get this exception:
SecurityException: Permission Denial: opening provider com.android.externalstorage.ExternalStorageProvider from ProcessRecord ... requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
On Android 10- everything works.
So, how can I save a file to the selected folder on Android 11?

Related

iOS APP cannot launch successfully after updated from Apple Store

In my flutter iOS app, every time the app is launched, it would call PathProvider.getApplicationDocumentsDirectory() to get the app documents directory to access to the previously saved data. If I install the app on an iOS device(not update here), the app could work exactly as expected. But if I updated the app from Apple Store or from Xcode, the app cannot longer be launched successfully. When I try to debug, I found the app caught exceptions at working with the drectory returned by PathProvider.getApplicationDocumentsDirectory(). Anybody could give some suggestions for fixing this? Thanks in advance.
For more information, when launched, my app has to execute createSync(recursive=true) if it does not find some app documents directories where I would store user-generated data. The app documents directories are returned by PathProvider.getApplicationDocumentsDirectory. However, after I updated the app, and when launched the app, PathProvider.getApplicationDocumentsDirectory() could still return a directory which has appropriate pattern, but the returned directory may not be the right directory since my app failed to find previously created folders there, so the app had to create the relevant directory for storing user-generated data again, and then I always got the error as below
FileSystemException: Creation failed (OS Error: Operation not permitted, errno = 1)
when I tried to create the directory with createSync(recursive=true), and no matter the version of path_provider was 1.20 or 1.10, the phenomenon persisted. Please help.
I assume the error you got is both happened in iOS simulator & iOS device ?
Get the path
Would you mind try to run on iOS simulator, and print out the path of the folder you try to access.
Open the folder in Finder
And with the printed folder path, you can open the folder with Finder by Cmd + G.
The error
Your mentioned error usually is because accessing the folder not belong to the app.
Let's see more after you print out the folder path.

How to open database sqlite file on iPhone real device?

I'm debbuging a app in my real device by cable. I've a iPhone 6. I want check my database and operate with sqlite3 to query my results. The other questions and tutorials explain to do this only in simulator but I'm using a real iPhone.
In AppDelegate, I prints the path of database:
print(NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).last! as String)
/Users/myname/Library/Developer/CoreSimulator/Devices/DAE93E57-7004-45F6-9B93-E79CA1AEEEFA/data/Containers/Data/Application/D7A4F27E-6F11-4941-A1B0-0337ABF788AB/Documents
So, I take the path and access from terminal and access my database with sqlite3 DatabaseFile
But when I debugging in my device, the path that's printed not works. I tried use the printed path
cd /var/mobile/Containers/Data/Application/3257D423-C198-41A5-B29D-B31E99F84F34/Documents
/usr/bin/CD: line 4: cd: /var/mobile/Containers/Data/Application/3257D423-C198-41A5-B29D-B31E99F84F34/Documents: No such file or directory
This error happens because this is of iOS system, I think.
Xcode 10.1
In Xcode, go to Window > Devices and Simulators
In the Devices tab, select your application, then click on the Gear icon, then click Download Container...
Choose the location you want to save the file, then click on Save.
Go to Finder and find the .xcappdata file you just downloaded, then right click and select Show Package in Contents
The contents folder will open. Your .sql file is in AppData > Library > Application Support
I recommend downloading DB Browser for SQL File, and opening the .sql file with that. It works wonders!
In recent versions of Xcode (8 and up, I think), open this with Window menu --> Devices. Find the device in the device list and look at the installed apps list for the device. Each app that you've built and installed on the device will be listed (and maybe some others). Select your app and click the gear menu below the list. Clicking the "Download" item on the pop-up menu will enable you to copy the app's documents, library, and other directories to your Mac.
NB: This will download an .xcappdata file. Right-clicking on that and selecting "Show Package Contents" will allow you to drill down to the actual sqlite file.
Here's another way:
In debug mode, add a UIActivityViewController to share(copy) your SQLite database to a Mac or to a third party iOS app like SQLiteFlow(iOS), then you can debug your SQLite database.
Files that you've placed in the Documents directly should show up in File Sharing inside iTunes. You can download them locally and edit them there. You'll need to enable it in your app's Info.plist by adding:
<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
The second key is actually only required if you want to enable showing these in the Files app.
You cannot access the .sqlite file in realtime when you debug your app using a device. Try accomplishing the same in the simulator and it will work.

Edit data with new Device File Explorer in Android Studio 3.1

With a new Device File Explorer in Android Studio 3.1 I can open file from the device and see it's contents in Android Studio
File opens in edit mode and when I add some lines, save it and restart Android Studio and open this file again it's still empty.
Is there a way to save my changes to the device without clicking upload, locate and manually enter this file path?
You have to save the file on your computer, edit it and upload back the file on the device.

Debugging Realm in iOS 8.3

I need to export .realm from Documents folder on real iOS device. Since iOS 8.3 Apple has disabled direct access to device's Documents folder how can I do that. For example I can send it by email, but is there any easier way?
You can download a device's container for your app from Xcode's "Devices" window with the following steps:
Connect your device to your Mac.
In the Devices window under Devices, select your device.
Under Installed Apps, select the app from the list.
From the Action menu (the gear icon), choose a menu item:
Show Container. A dialog shows the file contents of the container.
Download Container. In the dialog that appears, enter a location and click Save. The saved file will have a .xcappdata extension.
Replace Container. In the dialog that appears, select a file with a .xcappdata extension, and click Open.
Source: https://developer.apple.com/library/ios/recipes/xcode_help-devices_organizer/articles/manage_containers.html
You can still get to the Documents folder on a simulator. To find the folder of the simulator you're running on, first type the following in Terminal:
xcrun simctl list
And note the UUID of the simulator you're currently using.
Then navigate to ~/Library/Developer/CoreSimulator/Devices/<Simulator UUID>/data/Containers/Data/Application/<Application UUID>/Documents/.
You could also, in your app's code somewhere, get the path of your app's Document's folder and print it to the console with NSLog. Then copy the path, switch to Finder and press Shift-Cmd-G. Paste the path into the Finder field and it will take to your Documents folder.

iOS Uploading to AppStore - Unable to create configuration directory

iOS App Upload to app store (XCODE) fails saying:
"Unable to create configuration directory. Cannot save local copy of remote diagonistic configuration; local path is not writable."
Any ideas/thoughts?
ANSWER
Simple thing that solved it:
Right Click on your Home folder & Click Get Info.
Uncheck the Locked Checkbox.

Resources