a94_89Chauhan
a94_89Chauhan

Reputation: 11

Store the Firebase token in database

On token Refresh generate the Refresh token and store in database when the application is Installed.

Token Generated Code:

[Service]

[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class MyFirebaseIIDService : FirebaseInstanceIdService 
{
    const string TAG = "MyFirebaseIIDService";
    //string refreshedToken;
    private HttpClient client = new HttpClient();

    public override void OnTokenRefresh()
    {

       var refreshedToken = FirebaseInstanceId.Instance.Token;
       Log.Debug(TAG, "Refreshed token: " + refreshedToken);
        SendRegistrationToServer(refreshedToken);            
    }}

Upvotes: 1

Views: 1010

Answers (1)

Billy Liu
Billy Liu

Reputation: 2168

You could use the SqlConnection Class in SendRegistrationToServer() method to connect to your sql server.

For example:

    void SendRegistrationToServer(string token)
    {
        using (SqlConnection connection = new SqlConnection(yourconnectionString))
        {
            SqlCommand command = new SqlCommand("INSERT INTO table1 (id, token) VALUES('1', '" + token + "')", connection);
            command.Connection.Open();
            command.ExecuteNonQuery();
        }
    }

Upvotes: 1

Related Questions