2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Android】絵文字判定

Last updated at Posted at 2022-03-03

はじめに

絵文字かどうかを判定する方法について説明。こちらの記事でも書いたが、ここではgetEmojiMatchを使用する方法について説明。

コード

ビルド依存関係を追加

emoji2ライブラリを追加。

build.gradle
implementation "androidx.emoji2:emoji2:1.1.0"

処理内容

getEmojiMatchメソッドの第1引数は判定したいテキスト、第2引数はmetadataVersionを入れている。

fun CharSequence.isEmoji(): Boolean {
	val editorInfo = EditorInfo()
	EmojiCompat.get().updateEditorInfo(editorInfo)
	val metadataVersion = (editorInfo.extras[EmojiCompat.EDITOR_INFO_METAVERSION_KEY] as? Int) ?: 0
	return EmojiCompat.get().getEmojiMatch(this, metadataVersion) == EmojiCompat.EMOJI_SUPPORTED
}
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?