Subversion Repositories SmartDukaan

Rev

Rev 15356 | Rev 17463 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15356 Rev 15588
Line 97... Line 97...
97
/*    String referrer;*/
97
/*    String referrer;*/
98
    MixpanelAPI mixpanel;
98
    MixpanelAPI mixpanel;
99
    GoogleCloudMessaging gcm;
99
    GoogleCloudMessaging gcm;
100
    Context context;
100
    Context context;
101
    String regId;
101
    String regId;
-
 
102
    String msg = "";
102
/*    EditText referralCode;*/
103
/*    EditText referralCode;*/
103
/*
104
/*
104
    String  invitationCode;
105
    String  invitationCode;
105
    final ArrayList<String> invitationCodeList = new ArrayList<String>();
106
    final ArrayList<String> invitationCodeList = new ArrayList<String>();
106
*/
107
*/
Line 765... Line 766...
765
            if(userData.getString("id",null)==null){
766
            if(userData.getString("id",null)==null){
766
                Session.getActiveSession().closeAndClearTokenInformation();
767
                Session.getActiveSession().closeAndClearTokenInformation();
767
                Session.setActiveSession(null);
768
                Session.setActiveSession(null);
768
                userDataEditor.clear().commit();
769
                userDataEditor.clear().commit();
769
            }else {
770
            }else {
770
                new pushApkData().execute(new UtilityFunctions().getDeviceInformation(getApplicationContext()));
771
                new  pushApkData().execute(new UtilityFunctions().getDeviceInformation(getApplicationContext()));
771
          /*      new gcmPushData().execute();*/
772
          /*      new gcmPushData().execute();*/
772
            }
773
            }
773
        }
774
        }
774
    }
775
    }
775
 
776
 
Line 806... Line 807...
806
 
807
 
807
    private void registerInBackground() {
808
    private void registerInBackground() {
808
        new AsyncTask<Void, Void, String>() {
809
        new AsyncTask<Void, Void, String>() {
809
            @Override
810
            @Override
810
            protected String doInBackground(Void... params) {
811
            protected String doInBackground(Void... params) {
811
                String msg = "";
-
 
-
 
812
 
812
                try {
813
                try {
813
                    if (gcm == null) {
814
                    if (gcm == null) {
814
                        gcm = GoogleCloudMessaging.getInstance(context);
815
                        gcm = GoogleCloudMessaging.getInstance(context);
815
                    }
816
                    }
816
                    regId = gcm.register(ProfitTillConstants.GOOGLE_SENDER_ID);
817
                    regId = gcm.register(ProfitTillConstants.GOOGLE_SENDER_ID);
817
                    Log.d("RegisterActivity", "registerInBackground - regId: "
818
                    Log.d("RegisterActivity", "registerInBackground - regId: "
818
                            + regId);
819
                            + regId);
819
                    msg = "Device registered, registration ID=" + regId;
820
                    msg = "Device registered";
820
 
821
 
821
                } catch (IOException ex) {
822
                } catch (IOException ex) {
822
                    msg = "Error :" + ex.getMessage();
823
                    msg = "Error :" + ex.getMessage();
823
                    Log.d("RegisterActivity", "Error: " + msg);
824
                    Log.d("RegisterActivity", "Error: " + msg);
824
                }
825
                }
Line 828... Line 829...
828
 
829
 
829
            @Override
830
            @Override
830
            protected void onPostExecute(String msg) {
831
            protected void onPostExecute(String msg) {
831
                /*Toast.makeText(getApplicationContext(),
832
                /*Toast.makeText(getApplicationContext(),
832
                        "Registered with GCM Server." + msg, Toast.LENGTH_LONG)
833
                        "Registered with GCM Server." + msg, Toast.LENGTH_LONG)
833
                        .show();*/
834
                        .show();
-
 
835
                        */
834
            }
836
            }
835
        }.execute(null, null, null);
837
        }.execute(null, null, null);
836
    }
838
    }
837
 
839
 
838
    /*private void storeRegistrationId(Context context, String regId) {
840
    /*private void storeRegistrationId(Context context, String regId) {
Line 847... Line 849...
847
    }*/
849
    }*/
848
    public String registerGCM() {
850
    public String registerGCM() {
849
 
851
 
850
        gcm = GoogleCloudMessaging.getInstance(this);
852
        gcm = GoogleCloudMessaging.getInstance(this);
851
        regId = getRegistrationId(context);
853
        regId = getRegistrationId(context);
852
 
-
 
853
        if (TextUtils.isEmpty(regId)) {
-
 
854
 
-
 
855
            registerInBackground();
854
        registerInBackground();
856
 
-
 
857
            Log.d("RegisterActivity",
-
 
858
                    "registerGCM - successfully registered with GCM server - regId: "
-
 
859
                            + regId);
-
 
860
        } else {
-
 
861
           /* Toast.makeText(getApplicationContext(),
-
 
862
                    "RegId already available. RegId: " + regId,
-
 
863
                    Toast.LENGTH_LONG).show();*/
-
 
864
        }
-
 
865
        return regId;
855
        return regId;
866
    }
856
    }
867
 
857
 
868
    private String getRegistrationId(Context context) {
858
    private String getRegistrationId(Context context) {
869
 
859
 
Line 912... Line 902...
912
                nameValuePairsGcm = new ArrayList<>();
902
                nameValuePairsGcm = new ArrayList<>();
913
                TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
903
                TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
914
                nameValuePairsGcm.add(new BasicNameValuePair("gcm_regid",regId));
904
                nameValuePairsGcm.add(new BasicNameValuePair("gcm_regid",regId));
915
                nameValuePairsGcm.add(new BasicNameValuePair("imeinumber",telephonyManager.getDeviceId()));
905
                nameValuePairsGcm.add(new BasicNameValuePair("imeinumber",telephonyManager.getDeviceId()));
916
                nameValuePairsGcm.add(new BasicNameValuePair("user_id",userData.getString("id",null)));
906
                nameValuePairsGcm.add(new BasicNameValuePair("user_id",userData.getString("id",null)));
-
 
907
                nameValuePairsGcm.add(new BasicNameValuePair("device_message",arg0[0]));
917
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
908
                httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
918
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsGcm));
909
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsGcm));
919
                HttpResponse response = httpclient.execute(httppost);
910
                HttpResponse response = httpclient.execute(httppost);
920
                HttpEntity entity = response.getEntity();
911
                HttpEntity entity = response.getEntity();
921
                int status = response.getStatusLine().getStatusCode();
912
                int status = response.getStatusLine().getStatusCode();
Line 988... Line 979...
988
    class NotificationOpenedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
979
    class NotificationOpenedData extends AsyncTask<ArrayList<NameValuePair>, Integer, String> {
989
 
980
 
990
        @Override
981
        @Override
991
        protected void onPreExecute() {
982
        protected void onPreExecute() {
992
            super.onPreExecute();
983
            super.onPreExecute();
-
 
984
            Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
-
 
985
                    GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
-
 
986
            t.send(new HitBuilders.EventBuilder()
-
 
987
                    .setCategory("Notification")
-
 
988
                    .setAction("Notification Opened Login")
-
 
989
                    .setLabel("For User Id " + userData.getString("id","0"))
-
 
990
                    .build());
993
        }
991
        }
994
 
992
 
995
        @Override
993
        @Override
996
        protected String doInBackground(ArrayList<NameValuePair>... arg0) {
994
        protected String doInBackground(ArrayList<NameValuePair>... arg0) {
997
 
995
 
Line 1063... Line 1061...
1063
            }
1061
            }
1064
        }
1062
        }
1065
        @Override
1063
        @Override
1066
        protected void onPostExecute(String result) {
1064
        protected void onPostExecute(String result) {
1067
            super.onPostExecute(result);
1065
            super.onPostExecute(result);
1068
            new gcmPushData().execute();
1066
            new gcmPushData().execute(msg);
1069
        }
1067
        }
1070
    }
1068
    }
1071
}
1069
}