I am trying to download a simple text file from OneDrive:
// get the DriveItem for 'test.txt' (Id = T_ID)
var file = await graphClient.Drives["me"].Items[T_ID].GetAsync();
Debug.Assert(file != null && file.File != null);
sb.Append(file.Name?.ToString());
sb.AppendLine(" Last modified: " + file.LastModifiedDateTime.ToString());
// download and display content
sb.AppendLine("File content:\n");
var stream = await graphClient.Drives["me"].Items[T_ID]
.Content
.GetAsync();
if (stream == null) sb.AppendLine("Stream is null");
else
{
try
{
using var reader = new StreamReader(stream);
sb.AppendLine($"{reader.ReadToEnd()}");
}
catch (Exception ex)
{
sb.AppendLine($"{ex.Message}");
}
}
'test.txt' simply contains the string "This is a test document", T_ID is its Id in the Drive.
I get:
Exception of type 'Android.OS.NetworkOnMainThread Exception' was thrown
I tried to modify the Android manifest including android:usesCleartextTraffic="true" - same result.
Notes:
- In Windows machine it works without any problem
- Uploading the same file does not throw any exception.