如何参数传递到从Android的HTML文件 [英] How to pass parameter into HTML file from android
问题描述
我可以显示在Android的WebView中well.Now HTML文件内容,我怎么能传递参数转换成HTML file.For ex.my HTML内容的视频播放器
我需要通过动态值(URL)转换成HTML文件播放动态video.My HTML文件位于资产folder.How我能做到这一点?
I can show up HTML file content in android webview well.Now how could i pass parameter into HTML file.For ex.my HTML content has an video player i need to pass dynamic values(URL) into HTML file for playing dynamic video.My HTML file is located on asset folder.How could i do this?
感谢。
推荐答案
而不是直接通过视频网址(以下你的例子),我会用在HTML文件中的标记。例如:
Instead of passing directly the video URL (following you example), i would have used tokens in the Html file. For example:
<embed src="$VIDEO_URL$" autostart="false" />
其中 $ VIDEO_URL $
将令牌至极将与真正的视频在运行时被替换网址
where the $VIDEO_URL$
will be the token wich will be replaced during the runtime with a real video URL
.
此外,因为你不能在运行时更改您的资产文件夹的内容,你应该在html文件的内容加载到一个字符串变量,并使用替换
方法来替代令牌一个真正的网址
,并最终传递字符串的网页视图。事情是这样的:
Also, since you cannot change the contents of your asset folder during runtime you should load the html file contents into a String variable and use the replace
method to replace the token with a real URL
and, finally, pass that string to your webview. Something like this:
//The html variable has the html contents of the file stored in the assets folder
//and real_video_url string variable has the correct video url
html = html.replace("$VIDEO_URL$", real_video_url);
webview.loadData(html, "text/html", "utf-8");
这篇关于如何参数传递到从Android的HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!