能否用应用内置Drawable资源替代托管图片制作Gboard贴纸包?
Hey there, great question! Unfortunately, right now Gboard's Sticker API doesn't support using locally bundled Drawable resources directly from your app.
Looking at the official code snippet you shared, the setImage() method explicitly expects a hosted image URL:
new Indexable.Builder("Sticker")
.setName("Bye")
// add url for sticker asset
.setImage("http://www.snoopysticker.com?id=1234")
// see: Support links to your app content section
.setUrl("http://sticker/canonical/image/bye")
// Set th...
The core reason here is that Gboard needs to fetch sticker assets over the network—your app's internal Drawables are sandboxed within your APK, and other apps like Gboard don't have direct access to them.
If you want to use your existing Drawable assets for Gboard stickers, here are your best options:
- Host the assets publicly: Upload your Drawable files to a cloud storage service or your app's backend, then pass the public, accessible URL to
setImage(). This is the official and most reliable approach. - Local server workaround (not recommended): You could spin up a temporary local HTTP server within your app to serve the Drawable resources as local URLs (like
http://localhost:8080/sticker.png). But this adds unnecessary complexity, may have compatibility issues across devices, and isn't a supported use case by Google.
内容的提问来源于stack exchange,提问作者Dick Lucas

