[Xamarin.Android] API-31: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///storage/emulated/0/Pictures/MyApplication/TargetFile.html typ=text/html flg=0x50000081 }

Yurno 21 Reputation points
2022-03-03T04:17:20.033+00:00

Hello there,

I found error on Android-12 or API-31.

"No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:///storage/emulated/0/Pictures/MyApplication/TargetFile.html typ=text/html flg=0x50000081 }"

Normally, I run application on API 27 and it can open file to preview.

179457-image.png

This is my code.
[url] = file:///storage/emulated/0/Pictures/MyApplication/TargetFile.html
[mimeType] = text/html

using Android.Content;  
using Android.Net;  
public static void OpenUrl(string url, string mimeType = null) {  
     Uri uri = Uri.Parse(url);  
     Intent intent = new Intent(Intent.ActionView);   
     intent.SetFlags(ActivityFlags.NoHistory|ActivityFlags.NewTask|ActivityFlags.GrantReadUriPermission|ActivityFlags.GrantPrefixUriPermission);  
     if (mimeType == null) intent.SetData(uri);  
     else intent.SetDataAndType(uri, mimeType);  
     Android.App.Application.Context.StartActivity(intent);  
}  

Can someone help me to solve this problem?
I thank you for the answer in advance.

P.S. My main language isn't English. If the words're used incorrectly, I apologize.

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2022-03-03T09:53:55.89+00:00

    Hello,​

    Is this TargetFile.html store in the public path? If so, you cannot access the public folder path for Android 11 or later, Please see this storage limitation

    Best Regards,

    Leon Lu


    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.