//implement below code if token is send to server
public void registBroadcastReceiver(){
        mRegistrationBroadcastReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                String action = intent.getAction();
                if(action.equals(QuickstartPreferences.REGISTRATION_READY)){
                }else if(action.equals(QuickstartPreferences.REGISTRATION_GENERATING)){
                }else if(action.equals(QuickstartPreferences.REGISTRATION_COMPLETE)){
                    Log.d(TAG, "token is set in gcm_token");
                    gcm_token = intent.getStringExtra("token");
                    Log.d(TAG, "gcm_token: " + gcm_token);
                    ConnectServer.getInstance().setAsncTask(new AsyncTask<String, Void, Boolean>() {
                        @Override
                        protected Boolean doInBackground(String... params) {
                            URL obj = null;
                            try {
                                obj = new URL("http://165.194.104.22:5000/gcm");
                                HttpURLConnection con = (HttpURLConnection) obj.openConnection();
                                //implement below code if token is send to server
                                con = ConnectServer.getInstance().setHeader(con);
                                con.setDoOutput(true);
                                String parameter = URLEncoder.encode("register_id", "UTF-8") + "=" + URLEncoder.encode(gcm_token, "UTF-8");
                                OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
                                wr.write(parameter);
                                wr.flush();
                                BufferedReader rd = null;
                                if (con.getResponseCode() == 200) {
                                    Log.d(TAG,"gcm_token is sent");
                                } else {
                                    rd = new BufferedReader(new InputStreamReader(con.getErrorStream(), "UTF-8"));
                                    Log.e(TAG,rd.readLine());
                                }
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            return null;
                        }
                        @Override
                        protected void onPostExecute(Boolean aBoolean) {
                        }
                    });
                    ConnectServer.getInstance().execute();
                }
            }
        };
    }
obj = new URL("http://165.194.104.22:5000/gcm");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//implement below code if token is send to server
con = ConnectServer.getInstance().setHeader(con);
con.setDoOutput(true);
Log.d(TAG, "token is set in gcm_token");
gcm_token = intent.getStringExtra("token");
Log.d(TAG, "gcm_token: " + gcm_token);
ConnectServer.getInstance().setAsncTask(new AsyncTask<String, Void, Boolean>() {
@Override
protected Boolean doInBackground(String... params) {
URL obj = null;
try {
obj = new URL("http://165.194.104.22:5000/gcm");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//implement below code if token is send to server
con = ConnectServer.getInstance().setHeader(con);
con.setDoOutput(true);
String parameter = URLEncoder.encode("register_id", "UTF-8") + "=" + URLEncoder.encode(gcm_token, "UTF-8");
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(parameter);
wr.flush();
BufferedReader rd = null;
if (con.getResponseCode() == 200) {
Log.d(TAG,"gcm_token is sent");
} else {
public void registBroadcastReceiver(){
mRegistrationBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(QuickstartPreferences.REGISTRATION_READY)){
}else if(action.equals(QuickstartPreferences.REGISTRATION_GENERATING)){
}else if(action.equals(QuickstartPreferences.REGISTRATION_COMPLETE)){
Log.d(TAG, "token is set in gcm_token");
gcm_token = intent.getStringExtra("token");
Log.d(TAG, "gcm_token: " + gcm_token);
ConnectServer.getInstance().setAsncTask(new AsyncTask<String, Void, Boolean>() {
@Override
protected Boolean doInBackground(String... params) {
URL obj = null;
try {
obj = new URL("http://165.194.104.22:5000/gcm");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
//implement below code if token is send to server
con = ConnectServer.getInstance().setHeader(con);
con.setDoOutput(true);
String parameter = URLEncoder.encode("register_id", "UTF-8") + "=" + URLEncoder.encode(gcm_token, "UTF-8");
OutputStreamWriter wr = new OutputStreamWriter(con.getOutputStream());
wr.write(parameter);
wr.flush();
BufferedReader rd = null;
if (con.getResponseCode() == 200) {
Log.d(TAG,"gcm_token is sent");
} else {
rd = new BufferedReader(new InputStreamReader(con.getErrorStream(), "UTF-8"));
Log.e(TAG,rd.readLine());
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Boolean aBoolean) {