question

PadhyNiladri-7484 avatar image
0 Votes"
PadhyNiladri-7484 asked LeonLu-MSFT commented

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


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.

dotnet-xamarin
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Can you share your type of attachments? If you cannot open it in webview, you can download it by DownloadManager, then open it in the local application.


0 Votes 0 ·

Any attachment such as PDF, excel, image etc. When I tap on the attachment from an email, the MyWebClient-> OnCreateWindow() method is getting called.

Android.Webkit.WebView.HitTestResult result = view.GetHitTestResult();
string data = result.Extra;
string type = result.Type;
If I tap on an anchor tag I am getting tapped link in data and type as SRC_ANCHOR_TYPE. But when I am tapping an attachment I am getting data as null and Type as UNKNOWN_TYPE.



Possible supported Types as per Android documenation.

https://developer.android.com/reference/android/webkit/WebView.HitTestResult

int ANCHOR_TYPE HitTestResult for hitting a HTML::a tag
int EDIT_TEXT_TYPE HitTestResult for hitting an edit text area
int EMAIL_TYPE HitTestResult for hitting an email address
int GEO_TYPE HitTestResult for hitting a map address
int IMAGE_ANCHOR_TYPE HitTestResult for hitting a HTML::a tag which contains HTML::img
int IMAGE_TYPE HitTestResult for hitting an HTML::img tag
int PHONE_TYPE HitTestResult for hitting a phone number
int SRC_ANCHOR_TYPE HitTestResult for hitting a HTML::a tag with src=http
int SRC_IMAGE_ANCHOR_TYPE HitTestResult for hitting a HTML::a tag with src=http + HTML::img
int UNKNOWN_TYPE Default HitTestResult, where the target is unknown






0 Votes 0 ·
LeonLu-MSFT avatar image LeonLu-MSFT PadhyNiladri-7484 ·

I found your UserAgentString, do not set android version: you can refer to this thread, set it again https://developer.chrome.com/docs/multidevice/user-agent/

0 Votes 0 ·

0 Answers