[BUG] How to open/view email attachments from outlook inside Webview (Android/iOS)

Padhy, Niladri 21 Reputation points
2022-05-10T09:00:42.02+00:00

Hi,
I am opening outlook email inside a webview. In the email I am able to open all links if available. But when I am opening any attachment then I am getting type as UNKNOW_TYPE and data as null. I have created a custom webview renderer and overrides WebChromeClient. Following is the sample code.

webView.Settings.SetSupportMultipleWindows(true);
webView.SetWebChromeClient(new MyWebClient());

public class MyWebClient : WebChromeClient
        {
            public override bool OnCreateWindow(Android.Webkit.WebView view, bool isDialog, bool isUserGesture, Message resultMsg)
            {
                try
                {
                    if (view != null)
                    {
                        Android.Webkit.WebView.HitTestResult result = view.GetHitTestResult();
                        string data = result.Extra;
                        if (!string.IsNullOrEmpty(data))
                        {
                            Context context = view.Context;
                            Intent browserIntent = new Intent(Intent.ActionView, Uri.Parse(data));
                            context.StartActivity(browserIntent);
                        }
                    }
                    return false;
                }
                catch (System.Exception ex)
                {
                    return false;
                }
            }
        }

I tried with setting custom UserAgent to detect the webview as desktop browser.

Android

webView.Settings.UserAgentString = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/20100101 Firefox/4.0";

iOS

CustomUserAgent = @"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.99 Safari/537.36";

The look and feel got changed in both iOS and Android. I am able to open attachments in iOS. In Android its opening the inbox page, but not opening any email, simply its selecting email.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,296 questions
{count} votes