Note that there are some explanatory texts on larger screens.

plurals
  1. POSend $_POST data to Android Webview
    primarykey
    data
    text
    <p>So I have this Android Application that's in WebView that should pass the data to a server(hosting site), unfortunately I can't do it so I need your help to solve this problem.</p> <p>I got most of the code from this site so, it might looked familiar to you.</p> <p>So I have this HTML file that initiate the function to send the data to a server.</p> <p><strong>watch_video.html</strong></p> <pre><code> var v_id = getUrlVars()["v_id"]; $.ajax({ url: "http://mysite.com/fbtest.php?json_callback=?", dataType: "jsonp text", //GET method is used type: "POST", //pass the data data: 'v_id=' + v_id, //Do not cache the page cache: false, //Cross Domain crossDomain: true, //success success: function (html) { alert(html); } </code></pre> <p>So in PHP file which in a server(hosting site) that uses cross domain here's the code:</p> <pre><code>&lt;?php include("includes/db.php"); header('content-type: application/json; charset=utf-8'); header('Access-Control-Allow-Origin: *'); $v_id = ($_POST['v_id']) ?$_POST['v_id'] : $_GET['v_id']; $dwatch=date("Y-m-d"); $twatch=date("H:i:s"); $query="insert into watched_videos (fb_id,vid,date_watched,time_watched) values('12345','".$v_id."','".$dwatch."','".$twatch."')"; $row = mysql_query($query); ?&gt; </code></pre> <p><strong>I tested this locally using XAMPP, it works it inserted the data in a database.</strong></p> <p>When I installed it in <strong>Android</strong>, and did the same function it <strong>didn't worked.</strong></p> <p><strong>Here's my MainActivity.java code:</strong></p> <pre><code>package namename.name; import android.os.Bundle; import android.annotation.SuppressLint; import android.app.Activity; import android.view.KeyEvent; import android.view.Menu; import android.webkit.WebSettings.PluginState; import android.webkit.WebView; public class MainActivity extends Activity { @SuppressLint("SetJavaScriptEnabled") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); WebView mWebView = null; mWebView = (WebView) findViewById(R.id.webtest); mWebView.getSettings().setPluginState(PluginState.ON); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl("file:///android_asset/www/indexbackup.html"); } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { WebView mWebView = null; mWebView = (WebView) findViewById(R.id.webtest); if(event.getAction() == KeyEvent.ACTION_DOWN){ switch(keyCode) { case KeyEvent.KEYCODE_BACK: if(mWebView.canGoBack() == true){ mWebView.goBack(); }else{ finish(); } return true; } } return super.onKeyDown(keyCode, event); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } } </code></pre> <p>So going back to what I've said before I initiated the function in WebView using JSONP it did not work. </p> <p>I was wondering if I have something to put in my android file or so.</p> <p>I would be glad if someone helps me.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload