bool OnCommitContentInternal(InputContentInfoCompat inputContentInfo, int flags) { if ((flags & InputConnectionCompat.InputContentGrantReadUriPermission) != 0) { try { inputContentInfo.RequestPermission(); } catch (Java.Lang.Exception e) { Log.Error(Tag, "InputContentInfoCompat#requestPermission() failed.", e); return(false); } } mMimeTypes.Text = string.Join(".", inputContentInfo.Description.FilterMimeTypes("*/*")); mContentUri.Text = inputContentInfo.ContentUri.ToString(); mLabel.Text = inputContentInfo.Description.Label; Android.Net.Uri linkUri = inputContentInfo.LinkUri; mLinkUri.Text = linkUri != null?linkUri.ToString() : "null"; mFlags.Text = FlagsToString(flags); mWebView.LoadUrl(inputContentInfo.ContentUri.ToString()); mWebView.SetBackgroundColor(Color.Transparent); // Due to the asynchronous nature of WebView, it is a bit too early to call // inputContentInfo.releasePermission() here. Hence we call IC#releasePermission() when this // method is called next time. Note that calling IC#releasePermission() is just to be a // good citizen. Even if we failed to call that method, the system would eventually revoke // the permission sometime after inputContentInfo object gets garbage-collected. mCurrentInputContentInfo = inputContentInfo; mCurrentFlags = flags; return(true); }
public bool OnCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) { bool permission_requested = false; bool processed = false; // read and display inputContentInfo asynchronously if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.NMr1 && (flags & InputConnectionCompat.InputContentGrantReadUriPermission) != 0) { try { inputContentInfo.RequestPermission(); permission_requested = true; } catch (Exception) { return(processed); } } if (inputContentInfo.LinkUri != null) { string url = inputContentInfo.LinkUri.ToString(); Page p = App.Current.MainPage.Navigation.NavigationStack.Last(); if (p != null && p.GetType() == typeof(SingleChatPage)) { string rx_pattern = @"^https://[A-Za-z0-9]+\.(tenor|giphy)\.com/[A-Za-z0-9_/=%\?\-\.\&]+$"; if (Regex.IsMatch(url, rx_pattern)) { ((SingleChatPage)p).onSend(url); processed = true; } } } else { Logging.error("Error adding keyboard content, LinkUri is null"); } if (permission_requested) { inputContentInfo.ReleasePermission(); } return(processed); }