Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UserLoginTask extends AsyncTask<Void, Void, Boolean>
- {
- String errormessage;
- @Override
- protected void onPreExecute()
- {
- logindialog = ProgressDialog.show(MainLogin.this,"Please wait...", "Logging in...", true);
- logindialog.setCancelable(true);
- logindialog.setOnCancelListener(new OnCancelListener()
- {
- @Override
- public void onCancel(DialogInterface arg0)
- {
- Toast.makeText(getBaseContext(), "login cancelling...", Toast.LENGTH_SHORT).show();
- mAuthTask.cancel(true);
- logindialog.dismiss();
- }
- });
- }
- @Override
- protected Boolean doInBackground(Void... params)
- {
- try
- {
- HttpClient httpclient = new DefaultHttpClient();
- String httpserver = "http://182.71.212.110/mscanner_demo";//"http://http://10.0.2.2:65320/UserDetail/GetIMEIDetails"; // // //replace code "http://mscanner.apphb.com";
- SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
- Editor editor = sharedPref.edit();
- editor.putString(getString(R.string.httpserver),httpserver);
- editor.commit();
- //server_validate_IMEI server_login_url http://localhost:65320/UserDetail/GetIMEIDetails
- //HttpPost httppost = new HttpPost(httpserver+ Constants.server_login_url);
- //List<NameValuePair> params1 = new ArrayList<NameValuePair>();
- //params1.add(new BasicNameValuePair("userId", userid.getText().toString()));
- //params1.add(new BasicNameValuePair("pwd", pswrd.getText().toString()));
- //TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
- //String imsistring = telephonyManager.getSubscriberId();
- //String imei = telephonyManager.getDeviceId();
- //for imei
- telephonyInfo = TelephonyInfo.getInstance(getBaseContext());
- String imeiSIM11 = telephonyInfo.getImeiSIM1();
- String imeiSIM22 = telephonyInfo.getImeiSIM2();
- HttpPost httppost = new HttpPost(httpserver+ Constants.server_validate_IMEI);
- List<NameValuePair> params1 = new ArrayList<NameValuePair>();
- params1.add(new BasicNameValuePair("IMEI1", imeiSIM11));//911383459371629 imeiSIM11
- params1.add(new BasicNameValuePair("IMEI2", imeiSIM22));//911383459371629 imeiSIM22
- httppost.setEntity(new UrlEncodedFormEntity(params1));
- HttpResponse response = httpclient.execute(httppost);
- HttpEntity entity = response.getEntity();
- BufferedReader in = new BufferedReader(new InputStreamReader(entity.getContent()));
- StringBuilder sb = new StringBuilder();
- String line = null;
- while ((line = in.readLine()) != null)
- {
- sb.append(line + "");
- }
- // Append Server Response To Content String
- Content = sb.toString();
- if(sb.toString().equalsIgnoreCase("USER NOT FOUND")||sb.toString().equalsIgnoreCase("FAIL")||sb.toString().equalsIgnoreCase("DETAILS NOT FOUND"))
- {
- if (sb.toString().equalsIgnoreCase("USER NOT FOUND"))
- {
- errormessage="IMEI no. not registered.";
- return false;
- }
- else if (sb.toString().equalsIgnoreCase("DETAILS NOT FOUND"))
- {
- errormessage="IMEI not found.Contact your IT administrator.";
- return false;
- }
- else if (sb.toString().equalsIgnoreCase("FAIL"))
- {
- errormessage="Technical issue";
- return false;
- }
- }
- else
- {
- JSONArray json = new JSONArray(Content);
- if (json.length() > 0)
- {
- try
- {
- JSONObject c = json.getJSONObject(0);
- //editor.putString(getString(R.string.loginuser), userid.getText().toString());
- //editor.commit();
- //editor.putString(getString(R.string.loginpassword),pswrd.getText().toString());
- //editor.commit();
- editor.putString(getString(R.string.foldername),"mscanner/new folder");
- editor.commit();
- editor.putString(getString(R.string.directory),"androiddms");
- editor.commit();
- editor.putString(getString(R.string.username),c.getString("FTP_USER"));
- editor.commit();
- editor.putString(getString(R.string.password),c.getString("FTP_PWD"));
- editor.commit();
- editor.putString(getString(R.string.ftpserver),c.getString("FTP_IP"));
- editor.commit();
- editor.putString(getString(R.string.db_ip),c.getString("DATABASE_IP"));// change
- editor.commit();
- editor.putString(getString(R.string.dbuser),c.getString("DATABASE_USER"));
- editor.commit();
- editor.putString(getString(R.string.dbpassword),c.getString("DATABASE_PWD"));
- editor.commit();
- editor.putString(getString(R.string.dbname),c.getString("DATABASE_NAME"));
- editor.commit();
- editor.putString(getString(R.string.circle),c.getString("CIRCLE"));
- editor.commit();
- editor.putString(getString(R.string.dist_code),c.getString("DIST_CODE"));
- editor.commit();
- editor.putString(getString(R.string.IMEI),c.getString("IMEI"));
- editor.commit();
- editor.putString(getString(R.string.ZONE),c.getString("ZONE"));
- editor.commit();
- editor.putString(getString(R.string.retailerID),c.getString("RetID"));
- editor.commit();
- editor.putString(getString(R.string.storageMode),"SD Card");
- editor.commit();
- //sharedPref.getString(context.getResources().getString(R.string.storageMode), "notSet");
- editor.apply();
- /*
- * There is no need of this
- *
- HttpPost httppost1 = new HttpPost(httpserver+ Constants.server_uploadlogindata);
- List<NameValuePair> params2 = new ArrayList<NameValuePair>();
- params2.add(new BasicNameValuePair("userId", userid.getText().toString()));
- httppost1.setEntity(new UrlEncodedFormEntity(params2));
- response= httpclient.execute(httppost1);
- entity = response.getEntity();
- in = new BufferedReader(new InputStreamReader(entity.getContent()));
- sb = new StringBuilder();
- line = null;
- while ((line = in.readLine()) != null)
- {
- sb.append(line + "");
- }
- */
- return true;
- }
- catch (Exception e)
- {
- errormessage=e.getMessage();
- return false;
- }
- }
- else
- {
- errormessage="Invalid Credentials";
- }
- }
- }
- catch (Exception ex)
- {
- errormessage=ex.getMessage();
- return false;
- }
- return false;
- }
- @Override
- protected void onPostExecute(final Boolean success)
- {
- mAuthTask = null;
- if (success)
- {
- logindialog.dismiss();
- Intent backserviceintent = new Intent(getBaseContext(), BackgroundService.class);
- startService(backserviceintent);
- Intent intent = new Intent();
- intent.setClass(MainLogin.this, MainActivity.class);
- startActivity(intent);
- finish();
- }
- else
- {
- logindialog.dismiss();
- toast= Toast.makeText(getApplicationContext(),errormessage, Toast.LENGTH_SHORT);
- toast.setGravity(Gravity.TOP|Gravity.CENTER_HORIZONTAL, 0, 150);
- toast.show();
- }
- }
- @Override
- protected void onCancelled()
- {
- mAuthTask = null;
- logindialog.dismiss();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement