Hello,
I'm trying to create an App for a android tablet to record collection data to a file then off load/copy the file to a PC to upload to a database.
According to your description, you want to copy files directly from Android to computer, which is not feasible. Because Android has a different file system than Windows. And Android has modified and restricted the permissions of external storage after 11, and you can no longer store files directly to external folders.
You could refer to the answer from Android 11 external storage access for more details.
To do this, you need to remediate the file to a relayed path that is accessible to both, and then get the file from Windows.
Please refer to the following code and documentation.
Step 1. Implement a way to save and share files.
public class FileHelperService
{
public void SaveFile(string filename)
{
var path = Path.Combine(Xamarin.Essentials.FileSystem.AppDataDirectory, filename);
// save the file
File.WriteAllText(path, "Hello World");
}
public async Task ShareFileAsync()
{
var fn = "test.db";
var file = Path.Combine(FileSystem.AppDataDirectory, fn);
await Share.RequestAsync(new ShareFileRequest
{
Title = "Share DB",
File = new ShareFile(file)
});
}
}
// This method can be called in the event that you can click on a button
private async void Button_Clicked(object sender, EventArgs e)
{
FileHelperService filehelper = new FileHelperService();
await filehelper.ShareFileAsync();
}
Step 2. With the Share method, you can relay your database file by mail and download it in Windows.
Please refer to Xamarin.Essentials: Share for more details.
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.