Hello,
Welcome to our Microsoft Q&A platform!
However, the url is always null. Thus leading to malformed Uri exception. What am I doing wrong here?
This is because the Intent
is not the one you put the data. When calling StartActivityForResult
to open the file system, this intent contains the download url. But you return back to the previous activity, the system will generate a new Intent. The intent just contains the file info you handled. This is why data.GetStringExtra("download_url")
returns null in OnActivityResult method.
To fix this, you could save the data to SharedPreferences
and retrive it in the OnActivityResult method. Or use Xamarin.Essentials.Preferences to store the url.
Intent intent = new Intent(Intent.ActionCreateDocument);
...
//save the download url to sharedPreference
StartActivityForResult(intent, 1001);
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if (requestCode == 1001 && resultCode == Result.Ok)
{
//retrive the url
}
}
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
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.