Skip to content Skip to sidebar Skip to footer

How Do I Detect A Webpage Form Submission In Android App

I've written an app for Android that uses a webview to submit information via check boxes to a MYSQl back end. Right now to exit from the webview, the user has to use the keys on

Solution 1:

I believe the issue with your if statement is the getHost() which will return only the host name (www.google.com) and not the whole URL. Try removing that and I believe your if statement will return true if it matches.

Solution 2:

Got it working, here is the fix for others:

publicclassWebViewActivityextendsActivity {

public WebView webView;
intbackButtonCount=0;
finalHandlermyHandler=newHandler();
publicvoidonCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.webview);
    Bundleextras= getIntent().getExtras();
        if(extras!=null){
            String rode=extras.getString("rode");
                     }
        Stringray= extras.getString("rode");

    webView = (WebView) findViewById(R.id.webView1);
    webView.getSettings().setJavaScriptEnabled(true);
    finalJavaScriptInterfacemyJavaScriptInterface=newJavaScriptInterface(this);

    webView.loadUrl("http://mywebsite.com/subDir/user_man.php?user=" + ray);
    webView.setWebViewClient(newWebViewClient());
    webView.addJavascriptInterface(myJavaScriptInterface, "ForwardFunction");
}


  publicclassJavaScriptInterface {
        Context mContext;

        JavaScriptInterface(Context c) {
            mContext = c;  }

        publicvoidgoHome(){
                Intentik=newIntent(WebViewActivity.this, GetUserEmail.class);
                startActivity(ik);
                finish();
                Toast.makeText(WebViewActivity.this,"Your choices have been updated", Toast.LENGTH_LONG).show();
        }
  }


 @OverridepublicbooleanonCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.action_bar_two, menu);
        returntrue; }

    @OverridepublicbooleanonOptionsItemSelected(MenuItem item) 
    {
    if(item.getItemId()==R.id.action_selected)
    {   Intentiw=newIntent(this,GetUserEmail.class);
        startActivity(iw);
        finish(); }
    elseif(item.getItemId()==R.id.action_cancel)
        { 
        Intentiw=newIntent(this,RegisterActivity.class);
        startActivity(iw);
        finish();
        }
    returntrue;
    }   
    publicvoidonBackPressed()
    {
        if(backButtonCount >= 1)
        {
            Intentintent=newIntent(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++;
        }
    }

}

Post a Comment for "How Do I Detect A Webpage Form Submission In Android App"