First of all I would like to ask am I trying to write to correct path or not? I would like to have a log file on device and currently it is created and maintained this way:
string documentsPath = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDocuments);
string filePath = Path.Combine(documentsPath, "Log.txt");
I mean is this the right place or is it better to store it somewhere else? For example in internal storage?
Second question if above is fine and can be as it is, why following is doing nothing on app startup. I mean it does not request permissions for External Storage management?
if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.ManageExternalStorage) != (int)Permission.Granted ||
ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) != (int)Permission.Granted)
{
this.RequestPermissions(new string[] { Manifest.Permission.ManageExternalStorage, Manifest.Permission.AccessFineLocation }, 0);
}
and following should be added in order to request External storage management permissions:
if (!Android.OS.Environment.IsExternalStorageManager)
{
Intent intent = new Intent();
intent.SetAction(Android.Provider.Settings.ActionManageAppAllFilesAccessPermission);
Android.Net.Uri uri = Android.Net.Uri.FromParts("package", this.PackageName, null);
intent.SetData(uri);
this.StartActivity(intent);
}