GBoard Keyboard GIF Sticker Integration

ぃ、小莉子 提交于 2019-12-02 15:39:22

问题


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.

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

Please help.


回答1:


You need to implement the scheme:

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

 

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

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

 

The link directs you to this information:

"(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:
http://en.wikipedia.org/wiki/Open_Handset_Alliance,
http://developer.android.com/guide/topics/providers/content-providers.html

(file created 2012-09-23)".

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

...

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.

From: Creating a stub content provider:

...

Add a stub content provider

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:

In 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
}

...

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

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



来源:https://stackoverflow.com/questions/51263655/gboard-keyboard-gif-sticker-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!