Creating Keyboard Apps

Users interact with certain apps every day that are essential for them. These can be related to banking, notes, media, etc. Fleksy Keyboard SDK allows developers to build and place apps within the keyboard accessible via custom views.

Placing apps within the keyboard dramatically enhances the UX and allows the users to access the set apps anywhere for specific actions without leaving the currently open app. Fleksy provides existing apps that developers can use for the most common use cases. However, developers can also implement their app if a custom functionality is required.

Fleksy Apps

To use the Fleksy Apps, please note that you first need an API key that can be requested on the respective app’s developer website.

Fleksy currently provides the following keyboard apps:

Fleksy Apps Dependency Developer Portal
GiphyApp co.thingthing.fleksyapps:giphy:1.1.6 GIPHY Developers
StickersApp co.thingthing.fleksyapps:stickers:1.1.6 GIPHY Developers

Setup

Step 1

Add dependency for the required Fleksy Apps you wish to integrate in your keyboard app.

17
18
19
20
21
22
23
24
25
...
dependencies {
    ...
    // Fleksy Apps
    def fleksy_apps = "1.1.6"
    implementation "co.thingthing.fleksyapps:giphy:$fleksy_apps"
    implementation "co.thingthing.fleksyapps:stickers:$fleksy_apps"
}
...

The dependencies should be available in Fleksy’s maven repository.

Step 2

Add a provider to share media with other applications in your AndroidManifest file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="co.thingthing.samplekeyboard">
 
  <application
    ...
        <provider
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true"
            android:name="androidx.core.content.FileProvider">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>
     ...
  </application>
</manifest>

Step 3

Create or update the file paths xml file in the res/xml folder of your app to include both a root-path, if it didn’t exist before, and a files-path to the shared content folder.

Ensure that the content folder is unused and that includes the .nomedia path, to avoid other apps seeing the folder as a source of media files.

<?xml version="1.0" encoding="utf-8"?>
<paths>
    <root-path name="root" path="." />
    <files-path name="shared_media" path="SharedContent/.nomedia/" />
</paths>

Step 4

Configure the keyboard SDK to register apps.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class SampleKeyboardService : KeyboardService() {

    private val apps by lazy {
        listOf(
            GiphyApp(GIPHY_API_KEY),
            StickersApp(GIPHY_API_KEY)
        )
    }

    override fun createConfiguration(): KeyboardConfiguration {
        return KeyboardConfiguration(
            apps = KeyboardConfiguration.AppsConfiguration(
                keyboardApps = apps,
                shareAuthority = "$packageName.fileprovider",
                shareDirectory = "SharedContent",
                shareContentExpiration = TimeUnit.HOURS.toMillis(8)
            )
        )
    }

    companion object {
        const val GIPHY_API_KEY = "<api-key>"
    }

}

Read the SDK documentation for details of the AppsConfiguration on how to open an app.

GiphyApp

A Fleksy app to share GIFs from the GIPHY provider.

Example:

private val giphyApp by lazy {
    GiphyApp(
        apiKey = "<api-key>",
        icon = AppCompatResources.getDrawable(context, R.drawable.gif_icon),
        rating = "g",
        baseUrl = "https://api.giphy.com/",
        dynamicCategories = false,
        categories = listOf(
            CustomCategory(R.string.my_trending, "trending"),
            CustomCategory(R.string.my_fun, "fun")
        )
    )
}

Properties:

Property Type Description Default value
apiKey String The developer api key for Giphy none
icon Drawable? A drawable to use as an icon of the app. Visible on the app carousel and on the search bar. null
rating String Set the desired content rating. See GIPHY Ratings for details. It can be any of: g, pg, pg-13, r “g”
baseUrl String The base url of the giphy api service. Use to set proxies or content filtering services. https://api.giphy.com/
dynamicCategories Boolean Whether it should fetch dynamic categories provided by Giphy. true
categories List<CustomCategory>? When set, override the default or dynamic categories by these. null

StickersApp

A Fleksy app to share stickers from the GIPHY provider.

Example:

private val stickersApp by lazy {
    StickersApp(
        apiKey = "<api-key>",
        icon = AppCompatResources.getDrawable(context, R.drawable.sticker_icon),
        rating = "g",
        baseUrl = "https://api.giphy.com/",
        categories = listOf(
            CustomCategory(R.string.my_trending, "trending"),
            CustomCategory(R.string.my_fun, "fun")
        )
    )
}

Properties:

Property Type Description Default value
apiKey String The developer api key for Giphy none
icon Drawable? A drawable to use as an icon of the app. Visible on the app carousel and on the search bar. null
rating String Set the desired content rating. See GIPHY Ratings for details. It can be any of: g, pg, pg-13, r “g”
baseUrl String The base url of the giphy api service. Use to set proxies or content filtering services. https://api.giphy.com/
categories List<CustomCategory>? When set, override the default or dynamic categories by these. null

Custom Apps

BaseKeyboardApp

The base app module allows building apps following the carousel of images, categories, and search bar seen in the gifs and stickers apps.

A base app is constructed by extending the BaseKeyboardApp abstract class and implementing the required methods. To implement an App from the BaseKeyboardApp abstract class, add the base dependency to your project as an api dependency:

17
18
19
20
21
22
...
dependencies {
    ...
    api "co.thingthing.fleksyapps:base:1.0.9"
}
...

KeyboardApp

KeyboardApp is the core interface that the Fleksy Keyboard SDK understands and interacts with, upon which BaseKeyboardApp builds.

To implement an App from the KeyboardApp interface, add the core dependency to your project as a compileOnly dependency:

17
18
19
20
21
22
...
dependencies {
    ...
    compileOnly "co.thingthing.fleksyapps:core:1.0.9"
}
...

Additional Resources

For more information on working with keyboard apps, consider checking out the API reference documentation for the Fleksy Apps, which documents all the available methods to build apps for the keyboard built with Fleksy Keyboard SDK.


If something needs to be added or if you find an error in our documentation, please let us know either on our GitHub or Discord.

Last updated on May 22, 2024