package com.dahamit.dahammall;

import android.util.Log;

import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {

    private static final String TAG = "firebase";

    @Override
    public void onTokenRefresh() {
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();
        Log.d(TAG, " onTokenRefresh Refreshed token: " + refreshedToken);
        sendRegistrationToServer(refreshedToken);
    }
    private void sendRegistrationToServer(String token) {
        // TODO: Implement this method to send token to your app server.

         String phoneNum = "";
/*
        try{

            TelephonyManager telManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
       //     phoneNum = telManager.getLine1Number();
            if(phoneNum.startsWith("+82")){
                phoneNum = phoneNum.replace("+82", "0");
            }
            Log.d(TAG,"SecurityException phoneNum-"+phoneNum);

        }catch(SecurityException e){
            Log.d(TAG,"SecurityException e-"+e);


        }
        Log.d(TAG,"phonenuk-"+phoneNum);
        Log.d(TAG,"Token-"+token);

        OkHttpClient client = new OkHttpClient();
        RequestBody body = new FormBody.Builder().add("Phone", phoneNum).add("Token", token).build();
        Request request = new Request.Builder().url("http://www.vilatalk.com/fcm/register_token.php").post(body).build();
        try {
            client.newCall(request).execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        */
    }
}