gpt4 book ai didi

android - 图像键盘 : selecting rich content(Gif, 贴纸)重新打开 Activity

转载 作者:行者123 更新时间:2023-11-29 23:06:01 27 4
gpt4 key购买 nike

我正在尝试在我的应用中实现图像键盘支持。我关注了official documentation .为了支持这一点,我需要重写 EditTextonCreateInputConnection 来告诉软键盘支持什么应用程序以及获取所选内容 Uri 的回调。

编辑文本:

override fun onCreateInputConnection(editorInfo: EditorInfo): InputConnection {
val ic: InputConnection = super.onCreateInputConnection(editorInfo)
EditorInfoCompat.setContentMimeTypes(editorInfo, arrayOf("image/jpeg", "image/png"))

val callback =
InputConnectionCompat.OnCommitContentListener { inputContentInfo, flags, opts ->
val lacksPermission = (flags and
InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0
// read and display inputContentInfo asynchronously
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && lacksPermission) {
try {
inputContentInfo.requestPermission()
} catch (e: Exception) {
return@OnCommitContentListener false // return false if failed
}
}

// read and display inputContentInfo asynchronously.
// call inputContentInfo.releasePermission() as needed.

true // return true if succeeded
}
return InputConnectionCompat.createWrapper(ic, editorInfo, callback)
}

它工作正常。惊喜!!!

问题 是在我向 Activity 添加 Intent 过滤器时出现的。添加意向过滤器回调后,InputConnectionCompat.OnCommitContentListener 不再调用,它会使用支持的意向过滤器打开 Activity 。

list :

<activity
android:name=".Main2Activity"
android:label="@string/title_activity_main2">

<intent-filter> <-- this filter is added
<action android:name="android.intent.action.SEND"/>

<category android:name="android.intent.category.DEFAULT"/>

<data android:mimeType="image/*"/>
</intent-filter>
</activity>

sample 在 github 中可用提前致谢。

最佳答案

不确定为什么以及如何,但从

EditorInfoCompat.setContentMimeTypes(editorInfo, arrayOf("image/jpeg", "image/png"))

EditorInfoCompat.setContentMimeTypes(editorInfo, arrayOf("image/*"))

解决了问题

关于android - 图像键盘 : selecting rich content(Gif, 贴纸)重新打开 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56525255/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com