public class NotificationInstanceService extends FirebaseInstanceIdService {
private static final String TAG = "NotificationInstance";
@Override
public void onTokenRefresh() {
//Getting registration token
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
//Displaying token on logcat
Log.d(TAG, "Refreshed token: " + refreshedToken);
sendRegistrationToServer(refreshedToken);
}
private void sendRegistrationToServer(String token) {
//You can implement this method to store the token on your server
//Not required for current project
OkHttpClient client = new OkHttpClient();
//Create the request body
RequestBody body = new FormBody.Builder().add("Token", token).build();
//Know where to send the request to
Request request = new Request.Builder().url("<Application Server URL>/register.php")
.post(body)
.build();
//Create
try {
client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
}
client.newCall(request.execute(); if (isset($_POST["Token"])) {
$_uv_Token=$_POST["Token"];
$conn = mysqli_connect("/cloudsql/<database name url>","root","","FCM") or die("Error connecting");
$q="INSERT INTO users (Token) VALUES ( '$_uv_Token') "
." ON DUPLICATE KEY UPDATE Token = '$_uv_Token';";
var_dump(mysqli_query($conn,$q));
mysqli_query($conn,$q) or die(mysqli_error($conn));
mysqli_close($conn);
} else {
var_dump($_REQUEST);
}This would be a simple way to connect to my database and update the users database I created using the PHPMyAdmin console page.
3. After I created the script, I simply called
appcfg.py update .