【问题标题】:GBoard Keyboard GIF Sticker IntegrationGBoard 键盘 GIF 贴纸集成
【发布时间】:2018-07-10 11:09:00
【问题描述】:

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

@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());
    }

}

但我得到以下异常。

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

请帮忙。

【问题讨论】:

    标签: android keyboard gif gboard


    【解决方案1】:

    你需要实现方案:

    内容://schemeIETFBCP35”中进行了解释,引导您查看IANAUniform Resource Identifier (URI) Schemes”,其中进行了解释:

     

    URI 方案 |模板     |说明 |状态      |参考    |备注

    内容     | prov/content |内容      |临时 | Dave_Thaler | -

     

    该链接将您定向到此信息:

    "(最后更新时间为 2012-09-23)

    资源标识符 (RI) 方案名称:内容
    状态:暂定

    方案语法:
    内容://提供者/

    方案语义:
    访问 Android 内容提供程序。

    编码注意事项:
    未知,小心使用。

    使用此方案名称的应用程序/协议:
    对 Android 内容提供程序执行查询

    互操作性考虑:
    未知,请谨慎使用。
    可能不适合在公共互联网上公开使用。

    安全注意事项:
    未知,小心使用。

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

    作者/更改控制器:
    注册方或经过验证的代表
    方案创建者。请参阅上一个答案。

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

    (文件创建于 2012-09-23)”。

    更多信息请参考最后一个网址“Android Developers > Docs > Guides > Content providers”:

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

    ...

    许多其他类依赖于ContentProvider 类:

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

    发件人:Creating a stub content provider

    ...

    添加存根内容提供者

    要为您的应用创建存根内容提供程序,请扩展类 ContentProvider 并存根其所需的方法。以下 sn -p 向您展示了如何创建存根提供程序:

    在 Kotlin 中:

    /*
     * 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
    }
    

    ...

    在清单中声明提供者

    同步适配器框架通过检查您的应用是否在其应用清单中声明了提供程序来验证您的应用是否具有内容提供程序。要在清单中声明存根提供程序,请添加具有以下属性的 provider> 元素:

    ...

    <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。

    【讨论】:

      猜你喜欢
      • 2017-07-26
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-24
      • 1970-01-01
      相关资源
      最近更新 更多