android-GBoard键盘GIF贴纸集成

我正在尝试在我的应用程序中支持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());
    }

}

但是我收到以下异常.

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

请帮忙.

解决方法:

您需要实施该方案:

android-GBoard键盘GIF贴纸集成

内容:// schemeIETFBCP35”中进行了说明,该目录将指导您查看IANAUniform Resource Identifier (URI) Schemes”,在其中进行说明:

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

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

该链接将您引至以下信息:

“(last updated 2012-09-23)

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

Scheme syntax:
content://provider/

Scheme semantics:
Accessing an Android content provider.

Encoding considerations:
Unknown, use with care.

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

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

Security considerations:
Unknown, use with care.

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.

References:
07008,
07009

(file created 2012-09-23)”.

有关更多信息,请参考最后一个URL“ Android Developers > Docs > Guides > Content providers”:

“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 …

A number of other classes rely on the 070011 class:

  • 070012
  • 070013
  • 070014

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 070015.

从:Creating a stub content provider

Add a stub content provider

To create a stub content provider for your app, extend the class 070011 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
}

Declare the provider in the manifest

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 <070018> 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,以获取完整的文档以及此简短答案中未包含的其他链接.

上一篇:易初大数据-2019-10-13李宗盛专业英语


下一篇:如何为平板电脑开发定制的“非全屏”软键盘?