如何在安卓应用中检测网页表单提交
How Do I Detect a Webpage Form Submission In Android App
我为Android编写了一个应用程序,该应用程序使用Web视图通过复选框向MYSQl后端提交信息。 现在,若要退出 Web 视图,用户必须使用设备上的键继续执行下一个应用活动。有没有办法检测表单提交按钮已被应用程序按下,然后使用某些东西,比如说一个意图去下一个活动(关闭 webview,然后关闭 NextActivity.class),最好没有 javascript?我已经尝试了一个应该OverrideUrlLoad,方法是在按下提交按钮时调用一个新页面,然后用(Uri.parse(url).getHost().equals("page url")){Intent...}调用if语句,但没有运气。提前感谢!这是编码页面:
public class WebViewActivity extends Activity {
private WebView webView;
int backButtonCount = 0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
//webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
Bundle extras = getIntent().getExtras();
if(extras!=null){
String rode=extras.getString("rode");
}
String ray = extras.getString("rode");
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://mywebsite.com/SubDir/user_man.php?user=" + ray);
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).equals("http://mywebsite.com/SubDir/process_prof.php")) {
return false;
}
Intent ik = new Intent(WebViewActivity.this, master_menu.class);
startActivity(ik);
finish();
return true;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.action_bar_two, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.action_selected){
Intent iw = new Intent(this,GetUserEmail.class);
startActivity(iw);
finish();
}
else
if (item.getItemId()==R.id.action_cancel){
Intent iw = new Intent(this,RegisterActivity.class);
startActivity(iw);
finish();
}
return true;
}
public void onBackPressed()
{
if(backButtonCount >= 1)
{
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else
{
Toast.makeText(this, "Press the back button again to close.", Toast.LENGTH_SHORT).show();
backButtonCount++;
}
}
我相信
你的 if 语句的问题是 getHost(),它只会返回主机名 (www.google.com) 而不是整个 URL。尝试删除它,我相信如果匹配,您的 if 语句将返回 true。
让它工作,这是其他人的修复程序:
public class WebViewActivity extends Activity {
public WebView webView;
int backButtonCount = 0;
final Handler myHandler = new Handler();
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
Bundle extras = getIntent().getExtras();
if(extras!=null){
String rode=extras.getString("rode");
}
String ray = extras.getString("rode");
webView = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
final JavaScriptInterface myJavaScriptInterface = new JavaScriptInterface(this);
webView.loadUrl("http://mywebsite.com/subDir/user_man.php?user=" + ray);
webView.setWebViewClient(new WebViewClient());
webView.addJavascriptInterface(myJavaScriptInterface, "ForwardFunction");
}
public class JavaScriptInterface {
Context mContext;
JavaScriptInterface(Context c) {
mContext = c; }
public void goHome(){
Intent ik = new Intent(WebViewActivity.this, GetUserEmail.class);
startActivity(ik);
finish();
Toast.makeText(WebViewActivity.this,"Your choices have been updated", Toast.LENGTH_LONG).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.action_bar_two, menu);
return true; }
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
if(item.getItemId()==R.id.action_selected)
{ Intent iw = new Intent(this,GetUserEmail.class);
startActivity(iw);
finish(); }
else
if(item.getItemId()==R.id.action_cancel)
{
Intent iw = new Intent(this,RegisterActivity.class);
startActivity(iw);
finish();
}
return true;
}
public void onBackPressed()
{
if(backButtonCount >= 1)
{
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
else
{
Toast.makeText(this, "Press the back button again to close.", Toast.LENGTH_SHORT).show();
backButtonCount++;
}
}
}
相关文章:
- 如何检测网页中的更改并使用Javascript播放声音
- 如何检测网页是否已更改
- 是否可以检测网页上所有异步任务的完成情况
- 如何检测网页是由移动浏览器还是应用程序打开的
- 如何在安卓应用中检测网页表单提交
- 简单的谷歌浏览器扩展程序来检测网页上的点击 - 没有显示警报(错误)
- 需要检测网页中哪个<脚本>块与哪些其他<脚本>块交互
- 是否可以检测网页是否显示在Infragistics igDialog中
- 如何检测网页中的点击劫持攻击
- 我可以检测网页中是否存在扩展吗
- 如何使用PhantomJS检测网页的背景颜色
- 检测网页中的实际内容(忽略页眉,页脚,导航等)
- 如何检测网页的结尾?
- 我可以查询/检测网页用户的双击速度吗?
- 检测网页表单中的按键
- 如何使用javascript检测网页上的url
- 如何检测网页中是否有'多个html标签
- 如何检测网页中的移动设备
- 检测网页中的鼠标光标类型更改
- 如何检测网页中大多数不常见的超链接和隐式重定向