| 14792 |
manas |
1 |
package com.saholic.profittill;
|
|
|
2 |
|
|
|
3 |
import android.app.AlertDialog;
|
|
|
4 |
import android.app.ProgressDialog;
|
|
|
5 |
import android.content.Context;
|
|
|
6 |
import android.content.DialogInterface;
|
|
|
7 |
import android.content.Intent;
|
|
|
8 |
import android.content.SharedPreferences;
|
|
|
9 |
import android.net.ConnectivityManager;
|
| 16080 |
manas |
10 |
import android.net.Uri;
|
| 14792 |
manas |
11 |
import android.os.AsyncTask;
|
|
|
12 |
import android.os.Bundle;
|
|
|
13 |
import android.support.v7.app.ActionBarActivity;
|
|
|
14 |
import android.telephony.TelephonyManager;
|
| 14991 |
manas |
15 |
import android.util.Log;
|
| 14792 |
manas |
16 |
import android.view.Menu;
|
|
|
17 |
import android.view.MenuItem;
|
|
|
18 |
import android.widget.ProgressBar;
|
|
|
19 |
|
|
|
20 |
import com.google.android.gms.analytics.HitBuilders;
|
|
|
21 |
import com.google.android.gms.analytics.Tracker;
|
| 15588 |
manas |
22 |
import com.google.android.gms.gcm.GoogleCloudMessaging;
|
| 14792 |
manas |
23 |
import com.saholic.profittill.Constants.ProfitTillConstants;
|
| 14991 |
manas |
24 |
import com.saholic.profittill.Utils.UtilityFunctions;
|
| 14792 |
manas |
25 |
import com.saholic.profittill.main.GoogleAnalyticsTracker;
|
|
|
26 |
import com.saholic.profittill.main.LoginActivity;
|
|
|
27 |
import com.saholic.profittill.main.MainActivity;
|
|
|
28 |
import com.saholic.profittill.main.MobileNumber;
|
|
|
29 |
import com.saholic.profittill.main.ReferrerActivity;
|
|
|
30 |
import com.testin.agent.TestinAgent;
|
|
|
31 |
|
|
|
32 |
import org.apache.http.HttpEntity;
|
|
|
33 |
import org.apache.http.HttpResponse;
|
|
|
34 |
import org.apache.http.NameValuePair;
|
|
|
35 |
import org.apache.http.client.HttpClient;
|
|
|
36 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
37 |
import org.apache.http.client.methods.HttpPost;
|
|
|
38 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
39 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
40 |
import org.apache.http.util.EntityUtils;
|
|
|
41 |
import org.json.JSONArray;
|
|
|
42 |
import org.json.JSONObject;
|
|
|
43 |
|
| 15588 |
manas |
44 |
import java.io.IOException;
|
| 14792 |
manas |
45 |
import java.util.ArrayList;
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
public class SplashScreen extends ActionBarActivity {
|
|
|
49 |
SharedPreferences apiData, userData,apkData;
|
|
|
50 |
SharedPreferences.Editor apiEditor,userEditor,apkDataEditor;
|
| 14991 |
manas |
51 |
UtilityFunctions utilityFunctions;
|
| 14792 |
manas |
52 |
AlertDialog dialog1;
|
|
|
53 |
AlertDialog.Builder b;
|
|
|
54 |
ProgressBar pd;
|
| 15588 |
manas |
55 |
GoogleCloudMessaging gcm;
|
|
|
56 |
String regId;
|
| 14792 |
manas |
57 |
ArrayList<NameValuePair> apkDataListValue;
|
| 15588 |
manas |
58 |
ArrayList<NameValuePair> nameValuePairsGcm;
|
| 14792 |
manas |
59 |
@Override
|
|
|
60 |
protected void onCreate(Bundle savedInstanceState) {
|
|
|
61 |
TestinAgent.init(this);
|
|
|
62 |
super.onCreate(savedInstanceState);
|
|
|
63 |
setContentView(R.layout.activity_splash_screen);
|
|
|
64 |
getSupportActionBar().hide();
|
|
|
65 |
userData = getApplicationContext().getSharedPreferences("User_Data", MODE_PRIVATE);
|
|
|
66 |
apkData = getApplicationContext().getSharedPreferences("APK_Data", MODE_PRIVATE);
|
|
|
67 |
apiData = getApplicationContext().getSharedPreferences("API_Data", MODE_PRIVATE);
|
|
|
68 |
apkDataEditor = apkData.edit();
|
|
|
69 |
userEditor = userData.edit();
|
|
|
70 |
apiEditor = apiData.edit();
|
| 17057 |
manas |
71 |
String url="";
|
| 14792 |
manas |
72 |
Tracker t = ((GoogleAnalyticsTracker) getApplicationContext()).getTracker(
|
|
|
73 |
GoogleAnalyticsTracker.TrackerName.APP_TRACKER);
|
|
|
74 |
t.setScreenName("Splash Screen");
|
|
|
75 |
t.send(new HitBuilders.ScreenViewBuilder().build());
|
|
|
76 |
try {
|
|
|
77 |
String apkVersionCode = apkData.getString("versionCode","");
|
|
|
78 |
String apkVersionName = apkData.getString("versionName","");
|
|
|
79 |
if(userData.getString("id","").isEmpty()) {
|
|
|
80 |
|
|
|
81 |
}else {
|
|
|
82 |
if (apkVersionCode.isEmpty()) {
|
| 17057 |
manas |
83 |
/*PackageManager manager = this.getPackageManager();
|
|
|
84 |
PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
|
|
|
85 |
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
86 |
apkDataListValue = new ArrayList<>();
|
|
|
87 |
apkDataListValue.add(new BasicNameValuePair("user_id",userData.getString("id","")));
|
|
|
88 |
apkDataListValue.add(new BasicNameValuePair("versioncode",info.versionCode+""));
|
|
|
89 |
apkDataListValue.add(new BasicNameValuePair("versionname",info.versionName+""));
|
|
|
90 |
apkDataListValue.add(new BasicNameValuePair("osversion",android.os.Build.VERSION.SDK_INT+""));
|
|
|
91 |
apkDataListValue.add(new BasicNameValuePair("imeinumber",telephonyManager.getDeviceId()));
|
|
|
92 |
apkDataListValue.add(new BasicNameValuePair("manufacturer",Build.MANUFACTURER));
|
|
|
93 |
apkDataListValue.add(new BasicNameValuePair("model",Build.MODEL));
|
|
|
94 |
apkDataListValue.add(new BasicNameValuePair("brand",Build.BRAND));
|
|
|
95 |
apkDataEditor.putString("versionCode", info.versionCode + "");
|
|
|
96 |
apkDataEditor.putString("versionName", info.versionName);
|
|
|
97 |
apkDataEditor.putString("osVersion",android.os.Build.VERSION.SDK_INT+"");
|
|
|
98 |
apkDataEditor.putString("imeiNumber",telephonyManager.getDeviceId());*/
|
| 14991 |
manas |
99 |
utilityFunctions=new UtilityFunctions();
|
|
|
100 |
apkDataListValue = utilityFunctions.getDeviceInformation(this);
|
| 14792 |
manas |
101 |
|
|
|
102 |
if(isInternetOn()) {
|
|
|
103 |
new pushApkData().execute();
|
|
|
104 |
}
|
|
|
105 |
} else if (!(apkData.getString("checkId","blank").equalsIgnoreCase(userData.getString("id","blank")))) {
|
| 14991 |
manas |
106 |
utilityFunctions=new UtilityFunctions();
|
|
|
107 |
apkDataListValue = utilityFunctions.getDeviceInformation(this);
|
| 14792 |
manas |
108 |
if(isInternetOn()) {
|
|
|
109 |
new pushApkData().execute();
|
|
|
110 |
}
|
|
|
111 |
} else if (Integer.parseInt(apkVersionCode) == getPackageManager().getPackageInfo(getPackageName(), 0).versionCode) {
|
|
|
112 |
|
|
|
113 |
} else {
|
| 14991 |
manas |
114 |
utilityFunctions=new UtilityFunctions();
|
|
|
115 |
apkDataListValue = utilityFunctions.getDeviceInformation(this);
|
| 14792 |
manas |
116 |
if(isInternetOn()) {
|
|
|
117 |
new pushApkData().execute();
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
}
|
|
|
121 |
}catch (Exception e){
|
|
|
122 |
e.printStackTrace();
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
if(isInternetOn()){
|
|
|
127 |
new fetchAPISettings().execute();
|
|
|
128 |
}
|
|
|
129 |
else{
|
|
|
130 |
b= new AlertDialog.Builder(this);
|
|
|
131 |
b.setMessage("No internet connection. Please try again.");
|
|
|
132 |
b.setCancelable(false);
|
|
|
133 |
b.setPositiveButton("Retry", new DialogInterface.OnClickListener()
|
|
|
134 |
{
|
|
|
135 |
@Override
|
|
|
136 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
137 |
if(isInternetOn()){
|
|
|
138 |
new fetchAPISettings().execute();
|
|
|
139 |
dialog1.dismiss();
|
|
|
140 |
}
|
|
|
141 |
else{
|
|
|
142 |
dialog1 = b.create();
|
|
|
143 |
dialog1.show();
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
});
|
|
|
148 |
b.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
|
|
149 |
@Override
|
|
|
150 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
151 |
finish();
|
|
|
152 |
|
|
|
153 |
}
|
|
|
154 |
});
|
|
|
155 |
dialog1 = b.create();
|
|
|
156 |
dialog1.show();
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
|
|
|
163 |
@Override
|
|
|
164 |
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
165 |
// Inflate the menu; this adds items to the action bar if it is present.
|
|
|
166 |
getMenuInflater().inflate(R.menu.menu_splash_screen, menu);
|
|
|
167 |
return true;
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
@Override
|
|
|
171 |
public boolean onOptionsItemSelected(MenuItem item) {
|
| 17057 |
manas |
172 |
// Handle action bar item clicks here. The action bar will
|
|
|
173 |
// automatically handle clicks on the Home/Up button, so long
|
|
|
174 |
// as you specify a parent activity in AndroidManifest.xml.
|
| 14792 |
manas |
175 |
int id = item.getItemId();
|
| 17057 |
manas |
176 |
|
|
|
177 |
//noinspection SimplifiableIfStatement
|
| 14792 |
manas |
178 |
if (id == R.id.action_settings) {
|
|
|
179 |
return true;
|
|
|
180 |
}
|
|
|
181 |
|
|
|
182 |
return super.onOptionsItemSelected(item);
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
class fetchAPISettings extends AsyncTask<String, Integer, JSONObject> {
|
|
|
186 |
|
|
|
187 |
@Override
|
|
|
188 |
protected void onPreExecute() {
|
|
|
189 |
super.onPreExecute();
|
|
|
190 |
}
|
|
|
191 |
|
|
|
192 |
@Override
|
|
|
193 |
protected JSONObject doInBackground(String... arg0) {
|
|
|
194 |
try {
|
| 15588 |
manas |
195 |
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
| 14792 |
manas |
196 |
HttpClient httpclient = new DefaultHttpClient();
|
| 15588 |
manas |
197 |
String url = ProfitTillConstants.MOBILE_API+"?t="+apkData.getString("timestamp","0")+"&imeinumber="+telephonyManager.getDeviceId();
|
| 17057 |
manas |
198 |
//HttpPost httppost = new HttpPost(ProfitTillConstants.MOBILE_API+"?t="+apkData.getString("timestamp","0"));
|
| 15588 |
manas |
199 |
HttpPost httppost=new HttpPost(url);
|
| 14792 |
manas |
200 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
201 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
202 |
HttpEntity entity = response.getEntity();
|
|
|
203 |
JSONObject jObjGmail = new JSONObject(EntityUtils.toString(entity));
|
|
|
204 |
return jObjGmail;
|
|
|
205 |
|
|
|
206 |
} catch (Exception e) {
|
|
|
207 |
return null;
|
|
|
208 |
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
}
|
|
|
212 |
@Override
|
|
|
213 |
protected void onPostExecute(JSONObject result) {
|
|
|
214 |
super.onPostExecute(result);
|
|
|
215 |
if(result==null){
|
|
|
216 |
finish();
|
|
|
217 |
}
|
|
|
218 |
try {
|
|
|
219 |
JSONArray objects = result.getJSONArray("settings");
|
|
|
220 |
if(objects.length()==0){
|
|
|
221 |
System.out.println("Null settings array");
|
|
|
222 |
}else {
|
|
|
223 |
for (int i = 0; i < objects.length(); i++) {
|
|
|
224 |
JSONObject jsonObject = objects.getJSONObject(i);
|
|
|
225 |
JSONObject j = jsonObject.getJSONObject("Mobileappsetting");
|
|
|
226 |
apiEditor.remove(j.getString("setting"));
|
|
|
227 |
apiEditor.commit();
|
|
|
228 |
apiEditor.putString(j.getString("setting"), j.getString("value"));
|
|
|
229 |
apiEditor.commit();
|
|
|
230 |
}
|
|
|
231 |
}
|
|
|
232 |
String timestamp=result.getString("t");
|
| 15588 |
manas |
233 |
String failureCount=result.getString("failureCount");
|
| 14792 |
manas |
234 |
apkDataEditor.putString("timestamp",timestamp);
|
|
|
235 |
apkDataEditor.commit();
|
|
|
236 |
final String idCheck = userData.getString("id",null);
|
| 17057 |
manas |
237 |
//String check = userData.getString("which screen needs to be displayed");
|
| 15588 |
manas |
238 |
if(Integer.parseInt(failureCount)<=0) {
|
|
|
239 |
if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
|
| 18082 |
manas |
240 |
Intent startActivityIntent=new Intent(SplashScreen.this, ReferrerActivity.class);
|
|
|
241 |
Intent intent = getIntent();
|
|
|
242 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
243 |
Uri uri = intent.getData();
|
|
|
244 |
startActivityIntent.setAction("31");
|
|
|
245 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
246 |
}
|
|
|
247 |
startActivity(startActivityIntent);
|
|
|
248 |
//startActivity(new Intent(SplashScreen.this, ReferrerActivity.class));
|
| 15588 |
manas |
249 |
} else if (userData.getString("message", "false").equalsIgnoreCase("true")) {
|
| 18082 |
manas |
250 |
Intent startActivityIntent=new Intent(SplashScreen.this, MobileNumber.class);
|
|
|
251 |
Intent intent = getIntent();
|
|
|
252 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
253 |
Uri uri = intent.getData();
|
|
|
254 |
startActivityIntent.setAction("31");
|
|
|
255 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
256 |
}
|
|
|
257 |
startActivity(startActivityIntent);
|
|
|
258 |
//startActivity(new Intent(SplashScreen.this, MobileNumber.class));
|
| 15588 |
manas |
259 |
} else if (idCheck != null) {
|
| 16080 |
manas |
260 |
Intent startActivityIntent=new Intent(SplashScreen.this, MainActivity.class);
|
|
|
261 |
Intent intent = getIntent();
|
|
|
262 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
263 |
Uri uri = intent.getData();
|
|
|
264 |
startActivityIntent.setAction("31");
|
|
|
265 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
266 |
}
|
|
|
267 |
startActivity(startActivityIntent);
|
| 15588 |
manas |
268 |
} else {
|
| 18082 |
manas |
269 |
Intent startActivityIntent=new Intent(SplashScreen.this, LoginActivity.class);
|
|
|
270 |
Intent intent = getIntent();
|
|
|
271 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
272 |
Uri uri = intent.getData();
|
|
|
273 |
startActivityIntent.setAction("31");
|
|
|
274 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
275 |
}
|
|
|
276 |
startActivity(startActivityIntent);
|
|
|
277 |
//startActivity(new Intent(SplashScreen.this, LoginActivity.class));
|
| 14792 |
manas |
278 |
|
| 15588 |
manas |
279 |
}
|
|
|
280 |
}else{
|
|
|
281 |
registerGCM();
|
| 14792 |
manas |
282 |
}
|
|
|
283 |
}catch (Exception e){
|
|
|
284 |
finish();
|
|
|
285 |
}
|
|
|
286 |
}
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
class pushApkData extends AsyncTask<String, Integer, String> {
|
|
|
290 |
|
|
|
291 |
@Override
|
|
|
292 |
protected void onPreExecute() {
|
|
|
293 |
super.onPreExecute();
|
|
|
294 |
}
|
|
|
295 |
|
|
|
296 |
@Override
|
|
|
297 |
protected String doInBackground(String... arg0) {
|
|
|
298 |
try {
|
|
|
299 |
HttpClient httpclient = new DefaultHttpClient();
|
|
|
300 |
HttpPost httppost = new HttpPost("http://api.profittill.com/devices/add");
|
|
|
301 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
302 |
httppost.setEntity(new UrlEncodedFormEntity(apkDataListValue));
|
|
|
303 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
304 |
HttpEntity entity = response.getEntity();
|
|
|
305 |
int status = response.getStatusLine().getStatusCode();
|
|
|
306 |
|
|
|
307 |
if(status == 200){
|
|
|
308 |
apkDataEditor.putString("checkId",userData.getString("id",""));
|
|
|
309 |
apkDataEditor.commit();
|
|
|
310 |
return "success";
|
|
|
311 |
} else {
|
|
|
312 |
return "failure";
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
} catch (Exception e) {
|
|
|
316 |
return null;
|
|
|
317 |
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
}
|
|
|
321 |
@Override
|
|
|
322 |
protected void onPostExecute(String result) {
|
|
|
323 |
super.onPostExecute(result);
|
|
|
324 |
}
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
public final boolean isInternetOn() {
|
|
|
329 |
|
|
|
330 |
ConnectivityManager connection =
|
|
|
331 |
(ConnectivityManager)getSystemService(this.getBaseContext().CONNECTIVITY_SERVICE);
|
|
|
332 |
|
| 14991 |
manas |
333 |
if ( connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTED ||
|
| 14792 |
manas |
334 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTED ) {
|
|
|
335 |
|
|
|
336 |
/*Toast.makeText(this, " Connected ", Toast.LENGTH_LONG).show();*/
|
|
|
337 |
return true;
|
|
|
338 |
|
|
|
339 |
} else if (
|
| 14991 |
manas |
340 |
connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
|
|
341 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.CONNECTING ||
|
| 14792 |
manas |
342 |
connection.getNetworkInfo(0).getState() == android.net.NetworkInfo.State.DISCONNECTED ||
|
|
|
343 |
connection.getNetworkInfo(1).getState() == android.net.NetworkInfo.State.DISCONNECTED ) {
|
|
|
344 |
|
| 14991 |
manas |
345 |
/* Toast.makeText(this, " Not Connected ", Toast.LENGTH_LONG).show();*/
|
| 14792 |
manas |
346 |
return false;
|
|
|
347 |
}
|
|
|
348 |
return false;
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
private void showProgressDialog()
|
|
|
352 |
{
|
|
|
353 |
pDlg = new ProgressDialog(getApplicationContext());
|
|
|
354 |
pDlg.setIndeterminate(true);
|
|
|
355 |
pDlg.setCancelable(false);
|
|
|
356 |
pDlg.show();
|
|
|
357 |
}
|
|
|
358 |
|
|
|
359 |
ProgressDialog pDlg;
|
| 14991 |
manas |
360 |
|
| 17057 |
manas |
361 |
/*
|
|
|
362 |
|
|
|
363 |
@Override
|
|
|
364 |
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
|
|
365 |
Log.d("On Restore Instance","On Restore Instance");
|
|
|
366 |
super.onRestoreInstanceState(savedInstanceState);
|
|
|
367 |
}
|
|
|
368 |
|
|
|
369 |
@Override
|
|
|
370 |
protected void onRestart() {
|
|
|
371 |
Log.d("On Restart","On Restart");
|
|
|
372 |
super.onRestart();
|
|
|
373 |
|
|
|
374 |
try {
|
|
|
375 |
String apkVersionCode = apkData.getString("versionCode","");
|
|
|
376 |
String apkVersionName = apkData.getString("versionName","");
|
|
|
377 |
if(userData.getString("id","").isEmpty()) {
|
|
|
378 |
|
|
|
379 |
}else {
|
|
|
380 |
if (apkVersionCode.isEmpty()) {
|
|
|
381 |
apkDataListValue = getDeviceInformation();
|
|
|
382 |
|
|
|
383 |
if(isInternetOn()) {
|
|
|
384 |
new pushApkData().execute();
|
|
|
385 |
}
|
|
|
386 |
} else if (!(apkData.getString("checkId","blank").equalsIgnoreCase(userData.getString("id","blank")))) {
|
|
|
387 |
apkDataListValue = getDeviceInformation();
|
|
|
388 |
if(isInternetOn()) {
|
|
|
389 |
new pushApkData().execute();
|
|
|
390 |
}
|
|
|
391 |
} else if (Integer.parseInt(apkVersionCode) == getPackageManager().getPackageInfo(getPackageName(), 0).versionCode) {
|
|
|
392 |
|
|
|
393 |
} else {
|
|
|
394 |
apkDataListValue = getDeviceInformation();
|
|
|
395 |
if(isInternetOn()) {
|
|
|
396 |
new pushApkData().execute();
|
|
|
397 |
}
|
|
|
398 |
}
|
|
|
399 |
}
|
|
|
400 |
}catch (Exception e){
|
|
|
401 |
e.printStackTrace();
|
|
|
402 |
}
|
|
|
403 |
|
|
|
404 |
if(isInternetOn()){
|
|
|
405 |
new fetchAPISettings().execute();
|
|
|
406 |
}
|
|
|
407 |
else{
|
|
|
408 |
b= new AlertDialog.Builder(this);
|
|
|
409 |
b.setMessage("No internet connection. Please try again.");
|
|
|
410 |
b.setCancelable(false);
|
|
|
411 |
b.setPositiveButton("Retry", new DialogInterface.OnClickListener()
|
|
|
412 |
{
|
|
|
413 |
@Override
|
|
|
414 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
415 |
if(isInternetOn()){
|
|
|
416 |
new fetchAPISettings().execute();
|
|
|
417 |
dialog1.dismiss();
|
|
|
418 |
}
|
|
|
419 |
else{
|
|
|
420 |
dialog1 = b.create();
|
|
|
421 |
dialog1.show();
|
|
|
422 |
}
|
|
|
423 |
}
|
|
|
424 |
|
|
|
425 |
});
|
|
|
426 |
b.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
|
|
427 |
@Override
|
|
|
428 |
public void onClick(DialogInterface dialog, int which) {
|
|
|
429 |
finish();
|
|
|
430 |
|
|
|
431 |
}
|
|
|
432 |
});
|
|
|
433 |
dialog1 = b.create();
|
|
|
434 |
dialog1.show();
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
}
|
|
|
438 |
|
|
|
439 |
|
|
|
440 |
public ArrayList<NameValuePair> getDeviceInformation(){
|
|
|
441 |
ArrayList<NameValuePair> deviceDataList=null;
|
|
|
442 |
try {
|
|
|
443 |
PackageManager manager = this.getPackageManager();
|
|
|
444 |
PackageInfo info = manager.getPackageInfo(this.getPackageName(), 0);
|
|
|
445 |
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
446 |
deviceDataList = new ArrayList<>();
|
|
|
447 |
deviceDataList.add(new BasicNameValuePair("user_id", userData.getString("id", "")));
|
|
|
448 |
deviceDataList.add(new BasicNameValuePair("versioncode", info.versionCode + ""));
|
|
|
449 |
deviceDataList.add(new BasicNameValuePair("versionname", info.versionName + ""));
|
|
|
450 |
deviceDataList.add(new BasicNameValuePair("osversion", android.os.Build.VERSION.SDK_INT + ""));
|
|
|
451 |
deviceDataList.add(new BasicNameValuePair("imeinumber", telephonyManager.getDeviceId()));
|
|
|
452 |
deviceDataList.add(new BasicNameValuePair("manufacturer", Build.MANUFACTURER));
|
|
|
453 |
deviceDataList.add(new BasicNameValuePair("model", Build.MODEL));
|
|
|
454 |
deviceDataList.add(new BasicNameValuePair("brand", Build.BRAND));
|
|
|
455 |
apkDataEditor.putString("versionCode", info.versionCode + "");
|
|
|
456 |
apkDataEditor.putString("versionName", info.versionName);
|
|
|
457 |
apkDataEditor.putString("osVersion", android.os.Build.VERSION.SDK_INT + "");
|
|
|
458 |
apkDataEditor.putString("imeiNumber", telephonyManager.getDeviceId());
|
|
|
459 |
}catch (Exception e){
|
|
|
460 |
e.printStackTrace();
|
|
|
461 |
}
|
|
|
462 |
return deviceDataList;
|
|
|
463 |
}
|
|
|
464 |
*/
|
|
|
465 |
|
|
|
466 |
/*@Override
|
|
|
467 |
protected void onPause() {
|
|
|
468 |
Log.d("On Pause","On Pause");
|
|
|
469 |
super.onPause();
|
|
|
470 |
}*/
|
| 15588 |
manas |
471 |
public void registerGCM() {
|
|
|
472 |
|
|
|
473 |
gcm = GoogleCloudMessaging.getInstance(SplashScreen.this);
|
|
|
474 |
registerInBackground();
|
|
|
475 |
|
|
|
476 |
}
|
|
|
477 |
|
|
|
478 |
private void registerInBackground() {
|
|
|
479 |
new AsyncTask<Void, Void, String>() {
|
|
|
480 |
@Override
|
|
|
481 |
protected String doInBackground(Void... params) {
|
|
|
482 |
String msg = "";
|
|
|
483 |
try {
|
|
|
484 |
if (gcm == null) {
|
|
|
485 |
gcm = GoogleCloudMessaging.getInstance(SplashScreen.this);
|
|
|
486 |
}
|
|
|
487 |
regId = gcm.register(ProfitTillConstants.GOOGLE_SENDER_ID);
|
|
|
488 |
msg = "Device registered";
|
|
|
489 |
|
|
|
490 |
} catch (IOException ex) {
|
|
|
491 |
msg = "Error :" + ex.getMessage();
|
|
|
492 |
}
|
|
|
493 |
return msg;
|
|
|
494 |
}
|
|
|
495 |
|
|
|
496 |
@Override
|
|
|
497 |
protected void onPostExecute(String msg) {
|
|
|
498 |
new gcmPushData().execute(msg);
|
|
|
499 |
}
|
|
|
500 |
}.execute(null, null, null);
|
|
|
501 |
}
|
|
|
502 |
|
|
|
503 |
|
|
|
504 |
class gcmPushData extends AsyncTask<String, Integer, String> {
|
|
|
505 |
|
|
|
506 |
@Override
|
|
|
507 |
protected void onPreExecute() {
|
|
|
508 |
super.onPreExecute();
|
|
|
509 |
}
|
|
|
510 |
|
|
|
511 |
@Override
|
|
|
512 |
protected String doInBackground(String... arg0) {
|
|
|
513 |
String id = null;
|
|
|
514 |
try {
|
|
|
515 |
HttpClient httpclient = new DefaultHttpClient();
|
| 17057 |
manas |
516 |
HttpPost httppost = new HttpPost(apiData.getString("gcm.push.url", "http://staging.profittill.com/gcm_users/add"));
|
| 15588 |
manas |
517 |
nameValuePairsGcm = new ArrayList<>();
|
|
|
518 |
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
519 |
nameValuePairsGcm.add(new BasicNameValuePair("gcm_regid", regId));
|
|
|
520 |
nameValuePairsGcm.add(new BasicNameValuePair("imeinumber", telephonyManager.getDeviceId()));
|
|
|
521 |
nameValuePairsGcm.add(new BasicNameValuePair("user_id", userData.getString("id", null)));
|
|
|
522 |
nameValuePairsGcm.add(new BasicNameValuePair("device_message", arg0[0]));
|
|
|
523 |
httppost.setHeader("Authorization", ProfitTillConstants.BASIC_AUTH);
|
|
|
524 |
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairsGcm));
|
|
|
525 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
526 |
HttpEntity entity = response.getEntity();
|
|
|
527 |
int status = response.getStatusLine().getStatusCode();
|
|
|
528 |
|
|
|
529 |
if (status == 200) {
|
|
|
530 |
Log.d("ResponseCode GCM ", status + "");
|
|
|
531 |
} else {
|
|
|
532 |
Log.d("ResponseCode GCM ", status + "");
|
|
|
533 |
}
|
|
|
534 |
|
|
|
535 |
nameValuePairsGcm.clear();
|
|
|
536 |
Log.e("pass 1", "connection success ");
|
|
|
537 |
} catch (Exception e) {
|
|
|
538 |
Log.e("Fail 1", e.toString());
|
|
|
539 |
|
|
|
540 |
}
|
|
|
541 |
return id;
|
|
|
542 |
}
|
|
|
543 |
|
|
|
544 |
@Override
|
|
|
545 |
protected void onPostExecute(String result) {
|
|
|
546 |
super.onPostExecute(result);
|
|
|
547 |
final String idCheck = userData.getString("id",null);
|
|
|
548 |
if (userData.getString("referralCodeRequired", "false").equalsIgnoreCase("true")) {
|
| 18082 |
manas |
549 |
Intent startActivityIntent=new Intent(SplashScreen.this, ReferrerActivity.class);
|
|
|
550 |
Intent intent = getIntent();
|
|
|
551 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
552 |
Uri uri = intent.getData();
|
|
|
553 |
startActivityIntent.setAction("31");
|
|
|
554 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
555 |
}
|
|
|
556 |
startActivity(startActivityIntent);
|
|
|
557 |
//startActivity(new Intent(SplashScreen.this, ReferrerActivity.class));
|
| 15588 |
manas |
558 |
} else if (userData.getString("message", "false").equalsIgnoreCase("true")) {
|
| 18082 |
manas |
559 |
Intent startActivityIntent=new Intent(SplashScreen.this, MobileNumber.class);
|
|
|
560 |
Intent intent = getIntent();
|
|
|
561 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
562 |
Uri uri = intent.getData();
|
|
|
563 |
startActivityIntent.setAction("31");
|
|
|
564 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
565 |
}
|
|
|
566 |
startActivity(startActivityIntent);
|
|
|
567 |
//startActivity(new Intent(SplashScreen.this, MobileNumber.class));
|
| 15588 |
manas |
568 |
} else if (idCheck != null) {
|
| 16080 |
manas |
569 |
Intent startActivityIntent=new Intent(SplashScreen.this, MainActivity.class);
|
|
|
570 |
Intent intent = getIntent();
|
|
|
571 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
572 |
Uri uri = intent.getData();
|
|
|
573 |
startActivityIntent.setAction("31");
|
|
|
574 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
575 |
}
|
|
|
576 |
startActivity(startActivityIntent);
|
| 15588 |
manas |
577 |
} else {
|
| 18082 |
manas |
578 |
Intent startActivityIntent=new Intent(SplashScreen.this, LoginActivity.class);
|
|
|
579 |
Intent intent = getIntent();
|
|
|
580 |
if (Intent.ACTION_VIEW.equals(intent.getAction())) {
|
|
|
581 |
Uri uri = intent.getData();
|
|
|
582 |
startActivityIntent.setAction("31");
|
|
|
583 |
startActivityIntent.setData(Uri.parse(uri.toString()));
|
|
|
584 |
}
|
|
|
585 |
startActivity(startActivityIntent);
|
|
|
586 |
//startActivity(new Intent(SplashScreen.this, LoginActivity.class));
|
| 15588 |
manas |
587 |
}
|
|
|
588 |
}
|
|
|
589 |
}
|
| 17057 |
manas |
590 |
}
|