void DoCommitContent(string description, string mimeType, File file)
        {
            var editorInfo = CurrentInputEditorInfo;

            // Validate packageName again just in case.
            if (!ValidatePackageName(editorInfo))
            {
                return;
            }

            var contentUri = FileProvider.GetUriForFile(this, Authority, file);

            // As you as an IME author are most likely to have to implement your own content provider
            // to support CommitContent API, it is important to have a clear spec about what
            // applications are going to be allowed to access the content that your are going to share.
            int flag;

            if ((int)Build.VERSION.SdkInt >= 25)
            {
                // On API 25 and later devices, as an analogy of Intent.FLAG_GRANT_READ_URI_PERMISSION,
                // you can specify InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION to give
                // a temporary read access to the recipient application without exporting your content
                // provider.
                flag = InputConnectionCompat.InputContentGrantReadUriPermission;
            }
            else
            {
                // On API 24 and prior devices, we cannot rely on
                // InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION. You as an IME author
                // need to decide what access control is needed (or not needed) for content URIs that
                // you are going to expose. This sample uses Context.grantUriPermission(), but you can
                // implement your own mechanism that satisfies your own requirements.
                flag = 0;
                try
                {
                    // TODO: Use revokeUriPermission to revoke as needed.
                    GrantUriPermission(
                        editorInfo.PackageName, contentUri, ActivityFlags.GrantReadUriPermission);
                }
                catch (Exception e)
                {
                    Log.Error(Tag, "grantUriPermission failed packageName=" + editorInfo.PackageName
                              + " contentUri=" + contentUri, e);
                }
            }

            var inputContentInfoCompat = new InputContentInfoCompat(
                contentUri,
                new ClipDescription(description, new [] { mimeType }),
                null /* linkUrl */);

            InputConnectionCompat.CommitContent(
                CurrentInputConnection, CurrentInputEditorInfo, inputContentInfoCompat,
                flag, null);
        }
Exemple #2
0
            public override IInputConnection OnCreateInputConnection(EditorInfo editorInfo)
            {
                var ic = base.OnCreateInputConnection(editorInfo);

                EditorInfoCompat.SetContentMimeTypes(editorInfo, MimeTypes);
                var callback = new OnCommitContentListenerImpl()
                {
                    MimeTypes = MimeTypes, Owner = Owner
                };

                return(InputConnectionCompat.CreateWrapper(ic, editorInfo, callback));
            }
Exemple #3
0
        public override IInputConnection OnCreateInputConnection(EditorInfo outAttrs)
        {
            var ic = base.OnCreateInputConnection(outAttrs);

            outAttrs.ImeOptions = outAttrs.ImeOptions | Android.Views.InputMethods.ImeFlags.NoPersonalizedLearning;

            if (ic != null)
            {
                // allow image insertion
                EditorInfoCompat.SetContentMimeTypes(outAttrs, new string[] { "image/gif" });

                ic = InputConnectionCompat.CreateWrapper(ic, outAttrs, this);
            }

            return(ic);
        }