【发布时间】:2021-09-05 09:08:33
【问题描述】:
所以我正在创建一个具有 WebView 以在 html 中创建注释的应用程序。为此,我使用了一个名为 Rich Text Editor 的 GitHub 库(我将它放在我的应用项目文件夹中)
现在的问题是我想从我的主应用程序文件夹中调用我的函数。我怎么做?我想这样做的原因是因为我正在从我在其中一个类中使用“@JavascriptInterface”创建的 WebView 中检测到 Button onclick。当用户单击按钮时,我需要获取按钮中的值并将其用于主应用程序文件夹中的其他功能。 谁能帮帮我?
这是我的主应用文件夹中的 VideoViewingFragment
fun startsomething(vidTimestamp: Float){
youTubePlayerView.getYouTubePlayerWhenReady(object: YouTubePlayerCallback{
override fun onYouTubePlayer(youTubePlayer: YouTubePlayer) {
youTubePlayer.seekTo(vidTimestamp)}})}
这是我制作并放入富文本编辑器库中的 WebInterface 类:
class WebAppInterface(var mContext: Context) {
@JavascriptInterface
fun getString(text: String) {
//get text from the button click
// call the function from VideoViewingFragment
// This is where i want to call my functions from my activity in my other main app folder
}
这是从 .js 文件调用以调用 getStringFromButtonClick(在我的富文本编辑器库模块中)的 JavaScript 函数。每次点击都会调用这个函数。只有在用户创建了一个包含他们想要放入其中的任何文本的按钮之后......并且在它被点击之后,它才会被调用。
function myFunction(text){
window.Android.showToast(text);}
我知道这是一种非常糟糕的技术,因为它会导致代码注入。但这仅供我自己使用。
【问题讨论】:
标签: javascript java android kotlin import