Android的:如何保存的HTML文件,用户填写表单表单、文件、用户、Android

2023-09-03 20:48:35 作者:逢君二三事

我可以这种形式(从给定的URL)下载到我的SD卡:

I was able to download this form to my sdcard (from a given URL):

我的应用程序可以通过Android Web视图访问此表。我的问题是,如何将其用户装满后数据保存到一个文本文件的形式?我想保存在文本文件中由用户输入的数据,例如:

My app can access this form via the android web view. My question is, how to save it to a text file after a user filled data to the form? I want to save in the text file the data inputted by the user, for instance:

Address: User address here
City: User City
Province: User Province here
Zip: 4342343
Phone: 4534534534
What is your biggest regret in your life? None.

将被保存到文本文件... 我有点新的Java和Android开发。

will be saved to the text file... I'm kinda new to java and android dev.

推荐答案

如果你想在本地存储数据,您应该实现这种形式作为一个小部件为基础的活动而不是使用的WebView

If you want to store the data locally, you should implement this form as a widget-based Activity rather than using a WebView.

如果这些值应该由服务器处理,提交它像任何其他HTML表单,让服务器的HTTP POST请求挑值。

If these values should be processed by a server, submit it like any other HTML form and let the server pick the values from the HTTP POST request.

修改

有可能一个 WebViewClient 附加到的WebView ,允许在的WebView 的活动被称为从JavaScript。请参阅样本code 。

It is possible to attach a WebViewClient to the WebView, to allow methods in the WebView's Activity to be called from JavaScript. See sample code.

您的HTML文件需要包含在点击提交按钮时运行的JavaScript,收集表格的内容,然后将其传递给 WebViewClient

Your HTML file would need to contain JavaScript that runs when the "Submit" button is clicked, collects the contents of the form and then passes it to the WebViewClient.

(有可能是一个更简单的方法,请参见:Android调用JavaScript函数中的WebView )

(There might be an even easier way, see: Android Calling JavaScript functions in WebView)