I'm trying to insert the firebase token_key into the mysql using php script by Volley library but can't able to implement it.I'm facing "AuthFailureError" exception.
I know i'm doing some mistake but can't able to figure it out.I'm attaching the code snipet down here,Please give me some suggestions:
init.php
<?php
$host = "localhost";
$db_user = "root";
$db_password = "*****";
$db_name = "fcmdb";
$con = mysqli_connect($host,$db_user,$db_password,$db_name);
if($con)
echo "Connection Success...";
else
echo "Connection Failure...";
?>
fcm_insert.php
<?php
require "init.php";
$fcm_token ='';
$fcm_token = $_POST["key_token"];
$sql = "insert into fcm_info values('".$fcm_token."');";
mysqli_query($con,$sql);
mysqli_close($con);
?>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private Button btnClick;
String app_server_url="http://192.168.0.106:8079/fcmtest/fcm_insert.php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnClick=(Button)findViewById(R.id.button);
btnClick.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences sharedPreferences=getApplicationContext().getSharedPreferences(getString(R.string.FCM_PREF), Context.MODE_PRIVATE);
final String token=sharedPreferences.getString(getString(R.string.FCM_TOKEN),"");
StringRequest stringRequest=new StringRequest(Request.Method.POST, app_server_url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.i("Error",response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.i("Error",error.toString());
}
})
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params=new HashMap<String, String>();
params.put("key_token",token);
return params;
}
};
MySingleton.getMySingleton(MainActivity.this).addToRequestQueue(stringRequest);
}
});
}
}