GBoard键盘GIF贴纸集成 [英] GBoard Keyboard GIF Sticker Integration

查看:104
本文介绍了GBoard键盘GIF贴纸集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用程序中支持GBoard.我希望用户能够从GBoard中选择GIF.我的onCommitContent看起来像这样:

I am trying to support GBoard in my app. I want users to be able the select GIF from GBoard. My onCommitContent looks like this:

@Override
public void onCommitContent(InputContentInfoCompat inputContentInfo, int flags, Bundle opts) {
    try {
        if (inputContentInfo != null){
            if (inputContentInfo.getContentUri() != null){
                Log.v(inputContentInfo.getContentUri().getPath());
            }
            if (inputContentInfo.getLinkUri() != null){
                Log.v(inputContentInfo.getLinkUri().getPath());
            }
            Log.v((String)(inputContentInfo.getDescription().getLabel()));
            imageURI = "content://com.google.android.inputmethod.latin" + inputContentInfo.getContentUri().getPath() + inputContentInfo.getLinkUri().getPath();
        }
        Bitmap bitmap = MediaStore.Images.Media.getBitmap(activity.getContentResolver(), Uri.parse(imageURI));
        imageView.setImageBitmap(bitmap);
    } catch (Exception ex) {
        Log.v(ex.getMessage());
    }

}

但是我遇到了以下异常.

But I am getting the following exception.

没有内容提供者:content://com.google.android.inputmethod.latin

No content provider: content://com.google.android.inputmethod.latin

请帮助.

推荐答案

您需要实施该方案:

方案. ://www.ietf.org/about/"rel =" nofollow noreferrer> IETF " BCP35 ,它会指导您查看 IANA " 统一资源标识符(URI)方案",其解释如下:

The content:// scheme is explained in IETF "BCP35", which directs you to see IANA "Uniform Resource Identifier (URI) Schemes", where it is explained:

 

URI方案|模板      |描述状态        |参考书目  |笔记

URI Scheme | Template       | Description | Status         | Reference     | Notes

内容        | 省/内容 |内容    |临时| Dave_Thaler |       -

content         | prov/content | content       | Provisional | Dave_Thaler |       -

 

链接将您定向到此信息:

The link directs you to this information:

"(最近更新为2012-09-23)

"(last updated 2012-09-23)

资源标识符(RI)方案名称:content
状态:临时

Resource Identifier (RI) Scheme name: content
Status: provisional

方案语法:
内容://provider/

Scheme syntax:
content://provider/

方案语义:
访问Android内容提供商.

Scheme semantics:
Accessing an Android content provider.

编码注意事项:
未知,请谨慎使用.

Encoding considerations:
Unknown, use with care.

使用此方案名称的应用程序/协议:
在Android Content Provider上执行查询

Applications/protocols that use this scheme name:
Performs a query on an Android Content Provider

互操作性注意事项:
未知,请小心使用.
可能不适合在公共Internet上公开使用.

Interoperability considerations:
Unknown, use with care.
May be unsuitable for open use on the public internet.

安全注意事项:
未知,请谨慎使用.

Security considerations:
Unknown, use with care.

联系方式:
注册方:Dave Thaler
计划创建者:开放手机联盟

Contact:
Registering party: Dave Thaler
Scheme creator: Open Handset Alliance

作者/更改控制器:
注册方或经验证可以代表的人
方案创建者.请参阅先前的答案.

Author/Change controller:
Either the registering party or someone who is verified to represent
the scheme creator. See previous answer.

参考文献:
http://en.wikipedia.org/wiki/Open_Handset_Alliance
http://developer.android.com/guide/topics/providers/content-providers.html

References:
http://en.wikipedia.org/wiki/Open_Handset_Alliance,
http://developer.android.com/guide/topics/providers/content-providers.html

(文件创建于2012-09-23)".

(file created 2012-09-23)".

请参考最后一个网址" Android开发人员>文档>指南>内容提供商"以获取更多信息:

Refer to the last URL "Android Developers > Docs > Guides > Content providers" for more information:

内容提供者可以帮助应用程序管理对自身存储,由其他应用程序存储的数据的访问,并提供一种与其他应用程序共享数据的方式.它们封装数据并提供定义数据安全性的机制.内容提供者是连接一个进程中的数据和另一个进程中运行的代码的标准接口实现内容提供者有很多优点,最重要的是,您可以配置内容提供者以允许其他应用程序安全地访问和修改您的应用程序数据...

"Content providers can help an application manage access to data stored by itself, stored by other apps, and provide a way to share data with other apps. They encapsulate the data, and provide mechanisms for defining data security. Content providers are the standard interface that connects data in one process with code running in another process. Implementing a content provider has many advantages. Most importantly you can configure a content provider to allow other applications to securely access and modify your app data ...

...

许多其他类都依赖 ContentProvider 类:

A number of other classes rely on the ContentProvider class:

  • AbstractThreadedSyncAdapter
  • CursorAdapter
  • CursorLoader

如果您要使用这些类中的任何一个,您还需要在应用程序中实现内容提供程序.请注意,在使用同步适配器框架时,您也可以创建存根内容提供程序作为替代.有关此主题的更多信息,请参见创建存根内容提供商.

If you are making use of any of these classes you also need to implement a content provider in your application. Note that when working with the sync adapter framework you can also create a stub content provider as an alternative. For more information about this topic, see Creating a stub content provider.

来自:创建存根内容提供商 :

...

...

添加存根内容提供商

要为您的应用创建存根内容提供程序,请扩展类 ContentProvider ,并列出所需的方法.以下代码段显示了如何创建存根提供程序:

To create a stub content provider for your app, extend the class ContentProvider and stub out its required methods. The following snippet shows you how to create the stub provider:

在科特林:

/*
 * Define an implementation of ContentProvider that stubs out
 * all methods
 */
class StubProvider : ContentProvider() {
    /*
     * Always return true, indicating that the
     * provider loaded correctly.
     */
    override fun onCreate(): Boolean  = true

    /*
     * Return no type for MIME type
     */
    override fun getType(uri: Uri): String?  = null

    /*
     * query() always returns no results
     *
     */
    override fun query(
            uri: Uri,
            projection: Array<String>,
            selection: String,
            selectionArgs: Array<String>,
            sortOrder: String
    ): Cursor?  = null

    /*
     * insert() always returns null (no URI)
     */
    override fun insert(uri: Uri, values: ContentValues): Uri? = null

    /*
     * delete() always returns "no rows affected" (0)
     */
    override fun delete(uri: Uri, selection: String, selectionArgs: Array<String>): Int = 0

    /*
     * update() always returns "no rows affected" (0)
     */
    override fun update(
            uri: Uri,
            values: ContentValues,
            selection: String,
            selectionArgs: Array<String>
    ): Int = 0
}

...

...

在清单中声明提供者

同步适配器框架通过检查应用是否已在其应用清单中声明了提供者来验证您的应用具有内容提供者.要在清单中声明存根提供者,请添加< 提供者>元素:

The sync adapter framework verifies that your app has a content provider by checking that your app has declared a provider in its app manifest. To declare the stub provider in the manifest, add a <provider> element with the following attributes:

...

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.network.sync.BasicSyncAdapter"
    android:versionCode="1"
    android:versionName="1.0" >
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
    ...
    <provider
        android:name="com.example.android.datasync.provider.StubProvider"
        android:authorities="com.example.android.datasync.provider"
        android:exported="false"
        android:syncable="true"/>
    ...
    </application>
</manifest>

请参考以上URL,以获取完整的文档以及此简短答案中未包含的其他链接.

Please refer to the above URLs for complete documentation and further links not included in this short answer.

这篇关于GBoard键盘GIF贴纸集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆