android - 检测是否支持 unicode 字符?

标签 android unicode

我正在尝试组装一个可以随机向用户返回表情符号的小型 Android 应用程序。我的 Intent 是只使用实际的 unicode 表情符号字符,并将它们作为 unicode 字符串字符返回。

我构建了一个完整的 unicode 字符串数组,可以从中随机选择,而且很多都可以正确显示。然而,有些显示为不受支持的字符(一个带有 x 的矩形)。

显然不是每个平台都支持每个 unicode 表情符号字符,但如果可能的话,我想要一种方法来确定什么是受支持的字符,什么不是受支持的字符。理想的情况是查询支持的字符列表,但能够测试单个字符也能很好地完成这项工作。

最佳答案

另请查看 API 级别 23 中添加的 Paint.hasGlyph(String)。您可以使用它来测试表情符号等字符是否有可用的字形。

这就是documentation说:

boolean hasGlyph (String string)

Determine whether the typeface set on the paint has a glyph supporting the string. The simplest case is when the string contains a single character, in which this method determines whether the font has the character. In the case of multiple characters, the method returns true if there is a single glyph representing the ligature. For example, if the input is a pair of regional indicator symbols, determine whether there is an emoji flag for the pair.

Finally, if the string contains a variation selector, the method only returns true if the fonts contains a glyph specific to that variation.

Checking is done on the entire fallback chain, not just the immediate font referenced.

另见

关于android - 检测是否支持 unicode 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38162812/

相关文章:

java - 调整相机拍摄的照片大小以适合屏幕

java - 如何检查字节数组是否包含 Java 中的 Unicode 字符串?

c++ - WCHAR* 结尾包含垃圾

c++ - 将 CStringW 转换为 CString 结果问号

android - Android未在React Native中加载Webview

android - Jetpack Compose 1.0.0-alpha11如何手动导入扩展函数?

android - 获取有关 RealmRecyclerView 中的项目删除的通知

fortumo 应用内支付导致 Android 应用崩溃

php - 我应该为多字节字符串使用 mb_* 或 iconv_* 函数吗?

mysql - 删除经典 ASP/VBScript 中的四字节 UTF-8 字符(MySQL 相关)