List of usage examples for android.telephony TelephonyManager getDeviceId
@Deprecated
@SuppressAutoDoc
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public String getDeviceId()
From source file:org.hfoss.posit.android.RegisterActivity.java
/** * Logs the user onto the server, give the user's email and password. If * the user can successfully login, the phone receives an AUTHKEY, which is * saved in SharedPreferences.//from ww w. ja v a 2 s.c om * * Actually, this method makes two HTTP requests to the server, one to login * the user and a second to register the user's phone. * * @param email email account user is using to register with a given server * @param password password used to register and sign in to a server */ private void loginUser(String email, String password) { mProgressDialog = ProgressDialog.show(this, "Registering device", "Please wait.", true, true); String serverName = mSharedPrefs.getString("SERVER_ADDRESS", ""); Communicator com = new Communicator(this); TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); String imei = manager.getDeviceId(); // First login the user. String result = null; try { result = com.loginUser(serverName, email, password, imei); } catch (Exception e) { Log.i(TAG, "Exception " + e.getMessage()); } Log.i(TAG, "loginUser result: " + result); String authKey; if (null == result) { Utils.showToast(this, "Failed to get authentication key from server."); mProgressDialog.dismiss(); return; } //TODO this is still little uglyish String[] message = result.split(":"); if (message.length != 2 || message[1].equals("null")) { Utils.showToast(this, "Login failed: " + result); mProgressDialog.dismiss(); return; } // Successfully logged in if (message[0].equals("" + Constants.AUTHN_OK)) { authKey = message[1]; Log.i(TAG, "AuthKey " + authKey + " obtained, registering device"); // Here we register the device String responseString = com.registerDevice(serverName, authKey, imei); if (responseString.equals("true")) { Editor spEditor = mSharedPrefs.edit(); spEditor.putString("AUTHKEY", authKey); // Remember the AUTHKEY spEditor.putString("EMAIL", email); // Remember the userID spEditor.commit(); Intent intent = new Intent(this, ShowProjectsActivity.class); startActivity(intent); Utils.showToast(this, "Successfully logged in."); setResult(PositMain.LOGIN_SUCCESSFUL); finish(); } } else { Utils.showToast(this, message[1] + "\nMake sure you have connectivity" + " and a working server."); mProgressDialog.dismiss(); return; } mProgressDialog.dismiss(); }
From source file:com.samsung.android.remindme.SyncAdapter.java
@Override public void onPerformSync(final Account account, Bundle extras, String authority, final ContentProviderClient provider, final SyncResult syncResult) { Log.i(TAG, "onPerformSync called!"); TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); String clientDeviceId = tm.getDeviceId(); final long newSyncTime = System.currentTimeMillis(); final boolean uploadOnly = extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, false); final boolean manualSync = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false); final boolean initialize = extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, false); C2DMReceiver.refreshAppC2DMRegistrationState(mContext); Log.i(TAG, "Beginning " + (uploadOnly ? "upload-only" : "full") + " sync for account " + account.name); // Read this account's sync metadata final SharedPreferences syncMeta = mContext.getSharedPreferences("sync:" + account.name, 0); long lastSyncTime = syncMeta.getLong(LAST_SYNC, 0); long lastServerSyncTime = syncMeta.getLong(SERVER_LAST_SYNC, 0); // Check for changes in either app-wide auto sync registration information, or changes in // the user's preferences for auto sync on this account; if either changes, piggy back the // new registration information in this sync. long lastRegistrationChangeTime = C2DMessaging.getLastRegistrationChange(mContext); boolean autoSyncDesired = ContentResolver.getMasterSyncAutomatically() && ContentResolver.getSyncAutomatically(account, RemindMeContract.AUTHORITY); boolean autoSyncEnabled = syncMeta.getBoolean(DM_REGISTERED, false); // Will be 0 for no change, -1 for unregister, 1 for register. final int deviceRegChange; JsonRpcClient.Call deviceRegCall = null; if (autoSyncDesired != autoSyncEnabled || lastRegistrationChangeTime > lastSyncTime || initialize || manualSync) {//from www . jav a 2s .co m String registrationId = C2DMessaging.getRegistrationId(mContext); deviceRegChange = (autoSyncDesired && registrationId != null) ? 1 : -1; if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Auto sync selection or registration information has changed, " + (deviceRegChange == 1 ? "registering" : "unregistering") + " messaging for this device, for account " + account.name); } try { if (deviceRegChange == 1) { // Register device for auto sync on this account. deviceRegCall = new JsonRpcClient.Call(RemindMeProtocol.DevicesRegister.METHOD); JSONObject params = new JSONObject(); DeviceRegistration device = new DeviceRegistration(clientDeviceId, DEVICE_TYPE, registrationId); params.put(RemindMeProtocol.DevicesRegister.ARG_DEVICE, device.toJSON()); deviceRegCall.setParams(params); } else { // Unregister device for auto sync on this account. deviceRegCall = new JsonRpcClient.Call(RemindMeProtocol.DevicesUnregister.METHOD); JSONObject params = new JSONObject(); params.put(RemindMeProtocol.DevicesUnregister.ARG_DEVICE_ID, clientDeviceId); deviceRegCall.setParams(params); } } catch (JSONException e) { logErrorMessage("Error generating device registration remote RPC parameters.", manualSync); e.printStackTrace(); return; } } else { deviceRegChange = 0; } // Get the list of locally changed alerts. If this is an upload-only sync and there were // no local changes, cancel the sync. List<ModelJava.Alert> locallyChangedAlerts = null; try { locallyChangedAlerts = getLocallyChangedAlerts(provider, account, new Date(lastSyncTime)); } catch (RemoteException e) { logErrorMessage("Remote exception accessing content provider: " + e.getMessage(), manualSync); e.printStackTrace(); syncResult.stats.numIoExceptions++; return; } if (uploadOnly && locallyChangedAlerts.isEmpty() && deviceRegCall == null) { Log.i(TAG, "No local changes; upload-only sync canceled."); return; } // Set up the RPC sync calls final AuthenticatedJsonRpcJavaClient jsonRpcClient = new AuthenticatedJsonRpcJavaClient(mContext, Config.SERVER_AUTH_URL_TEMPLATE, Config.SERVER_RPC_URL); try { jsonRpcClient.blockingAuthenticateAccount(account, manualSync ? AuthenticatedJsonRpcJavaClient.NEED_AUTH_INTENT : AuthenticatedJsonRpcJavaClient.NEED_AUTH_NOTIFICATION, false); } catch (AuthenticationException e) { logErrorMessage("Authentication exception when attempting to sync. root cause: " + e.getMessage(), manualSync); e.printStackTrace(); syncResult.stats.numAuthExceptions++; return; } catch (OperationCanceledException e) { Log.i(TAG, "Sync for account " + account.name + " manually canceled."); return; } catch (RequestedUserAuthenticationException e) { syncResult.stats.numAuthExceptions++; return; } catch (InvalidAuthTokenException e) { logErrorMessage("Invalid auth token provided by AccountManager when attempting to " + "sync.", manualSync); e.printStackTrace(); syncResult.stats.numAuthExceptions++; return; } // Set up the alerts sync call. JsonRpcClient.Call alertsSyncCall = new JsonRpcClient.Call(RemindMeProtocol.AlertsSync.METHOD); try { JSONObject params = new JSONObject(); params.put(RemindMeProtocol.ARG_CLIENT_DEVICE_ID, clientDeviceId); params.put(RemindMeProtocol.AlertsSync.ARG_SINCE_DATE, Util.formatDateISO8601(new Date(lastServerSyncTime))); JSONArray locallyChangedAlertsJson = new JSONArray(); for (ModelJava.Alert locallyChangedAlert : locallyChangedAlerts) { locallyChangedAlertsJson.put(locallyChangedAlert.toJSON()); } params.put(RemindMeProtocol.AlertsSync.ARG_LOCAL_NOTES, locallyChangedAlertsJson); alertsSyncCall.setParams(params); } catch (JSONException e) { logErrorMessage("Error generating sync remote RPC parameters.", manualSync); e.printStackTrace(); syncResult.stats.numParseExceptions++; return; } List<JsonRpcClient.Call> jsonRpcCalls = new ArrayList<JsonRpcClient.Call>(); jsonRpcCalls.add(alertsSyncCall); if (deviceRegChange != 0) jsonRpcCalls.add(deviceRegCall); jsonRpcClient.callBatch(jsonRpcCalls, new JsonRpcClient.BatchCallback() { public void onData(Object[] data) { if (data[0] != null) { // Read alerts sync data. JSONObject dataJson = (JSONObject) data[0]; try { List<ModelJava.Alert> changedAlerts = new ArrayList<ModelJava.Alert>(); JSONArray alertsJson = dataJson.getJSONArray(RemindMeProtocol.AlertsSync.RET_NOTES); for (int i = 0; i < alertsJson.length(); i++) { changedAlerts.add(new ModelJava.Alert(alertsJson.getJSONObject(i))); } reconcileSyncedAlerts(provider, account, changedAlerts, syncResult.stats); // If sync is successful (no exceptions thrown), update sync metadata long newServerSyncTime = Util .parseDateISO8601( dataJson.getString(RemindMeProtocol.AlertsSync.RET_NEW_SINCE_DATE)) .getTime(); syncMeta.edit().putLong(LAST_SYNC, newSyncTime).commit(); syncMeta.edit().putLong(SERVER_LAST_SYNC, newServerSyncTime).commit(); Log.i(TAG, "Sync complete, setting last sync time to " + Long.toString(newSyncTime)); } catch (JSONException e) { logErrorMessage("Error parsing alert sync RPC response", manualSync); e.printStackTrace(); syncResult.stats.numParseExceptions++; return; } catch (ParseException e) { logErrorMessage("Error parsing alert sync RPC response", manualSync); e.printStackTrace(); syncResult.stats.numParseExceptions++; return; } catch (RemoteException e) { logErrorMessage("RemoteException in reconcileSyncedAlerts: " + e.getMessage(), manualSync); e.printStackTrace(); return; } catch (OperationApplicationException e) { logErrorMessage("Could not apply batch operations to content provider: " + e.getMessage(), manualSync); e.printStackTrace(); return; } finally { provider.release(); } } // Read device reg data. if (deviceRegChange != 0) { // data[1] will be null in case of an error (successful unregisters // will have an empty JSONObject, not null). boolean registered = (data[1] != null && deviceRegChange == 1); syncMeta.edit().putBoolean(DM_REGISTERED, registered).commit(); if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Stored account auto sync registration state: " + Boolean.toString(registered)); } } } public void onError(int callIndex, JsonRpcException e) { if (e.getHttpCode() == 403) { Log.w(TAG, "Got a 403 response, invalidating App Engine ACSID token"); jsonRpcClient.invalidateAccountAcsidToken(account); } provider.release(); logErrorMessage("Error calling remote alert sync RPC", manualSync); e.printStackTrace(); } }); }
From source file:com.fpil.android.remotesensor.MainDisplay.java
public void processData(final Intent data) { Toast.makeText(getContext(), "Received Info", Toast.LENGTH_SHORT).show(); myTalker.flushData(mChatService.inRedArray, mChatService.inGreenArray, mChatService.inBlueArray, mChatService.inCArray, mChatService.inLeafNumber, mChatService.incomingIndex, mChatService.leafIndex);//from www .j a v a2 s . c om data.putExtra(SuggestAndSave.red, mChatService.inRedArray); data.putExtra(SuggestAndSave.green, mChatService.inGreenArray); data.putExtra(SuggestAndSave.blue, mChatService.inBlueArray); data.putExtra(SuggestAndSave.C, mChatService.inCArray); TelephonyManager tmanager = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE); data.putExtra(SuggestAndSave.IMEI, tmanager.getDeviceId()); if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. // no location data, save without it saver.saveInfo(data); refreshCards(); } else { final long key_update = saver.saveInfo(data); refreshCards(); Toast.makeText(getActivity(), "Saved data, waiting for location", Toast.LENGTH_SHORT).show(); Log.d(TAG, "Waiting for location"); final long time = new Date().getTime(); LocationListener locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { if ((Math.abs(current.getAccuracy() - locAccuracy) < 20) || (new Date().getTime() - time > 3000)) { try { locationManager.removeUpdates(this); } catch (SecurityException e) { } Log.d(TAG, String.format("Lat: %f, Long: %f, Accuracy: %f", location.getLatitude(), location.getLongitude(), location.getAccuracy())); Toast.makeText(getActivity(), "Updated location", Toast.LENGTH_SHORT).show(); saver.updateLocation(key_update, location.getLatitude(), location.getLongitude()); refreshCards(); } } @Override public void onStatusChanged(String s, int i, Bundle bundle) { } @Override public void onProviderEnabled(String s) { } @Override public void onProviderDisabled(String s) { } }; locationManager.requestLocationUpdates(locationProviderName, 2000, 0, locationListener); } }
From source file:at.aec.solutions.checkmkagent.AgentService.java
private void writeDMIDecode(PrintWriter _out) { _out.write("<<<dmi_sysinfo>>>" + NEWLINE); _out.write("System Information" + NEWLINE); _out.write(" Manufacturer: " + Build.MANUFACTURER + " (" + Build.BRAND + ")" + NEWLINE); _out.write(" Product Name: " + Build.MODEL + NEWLINE); _out.write(" Version: " + Build.VERSION.RELEASE + NEWLINE); _out.write(" Serial Number: " + Build.DISPLAY + NEWLINE); TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String uuid = tManager.getDeviceId(); _out.write(" UUID: " + uuid + NEWLINE); _out.write(" Radio Version: " + Build.getRadioVersion() + NEWLINE); _out.write(" Wake-up Type: Power Switch" + NEWLINE); _out.write(" SKU Number: Not Specified" + NEWLINE); _out.write(" Family: Not Specified" + NEWLINE); }
From source file:org.hfoss.posit.android.RegisterActivity.java
/** * Handles server registration by decoding the JSON Object that the barcode * reader gets from the server site containing the server address and the * authentication key. These two pieces of information are stored as shared * preferences. The user is then prompted to choose a project from the * server to work on and sync with.// w w w. j a va 2 s . c o m */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.i(TAG, "Requestcode = " + requestCode + "Result code = " + resultCode); super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case LOGIN_BY_BARCODE_READER: String value = data.getStringExtra("SCAN_RESULT"); Log.i(TAG, "Bar code scanner result " + value); // Hack to remove extra escape characters from JSON text. StringBuffer sb = new StringBuffer(""); for (int k = 0; k < value.length(); k++) { char ch = value.charAt(k); if (ch != '\\') { sb.append(ch); } else if (value.charAt(k + 1) == '\\') { sb.append(ch); } } value = sb.toString(); // Valid JSON encoded string // End of Hack JSONObject object; try { Log.i(TAG, "JSON=" + value); object = new JSONObject(value); String server = object.getString("server"); String authKey = object.getString("authKey"); if (Utils.debug) Log.i(TAG, "server= " + server + ", authKey= " + authKey); TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); String imei = manager.getDeviceId(); Communicator communicator = new Communicator(this); mProgressDialog = ProgressDialog.show(this, "Registering device", "Please wait.", true, true); try { String registered = communicator.registerDevice(server, authKey, imei); Log.d(TAG, "onActivityResult, registered = " + registered); if (registered != null) { Log.i(TAG, "registered"); Editor spEditor = mSharedPrefs.edit(); spEditor.putString("SERVER_ADDRESS", server); spEditor.putString("AUTHKEY", authKey); spEditor.putInt("PROJECT_ID", 0); spEditor.putString("PROJECT_NAME", ""); spEditor.commit(); Intent intent = new Intent(this, ShowProjectsActivity.class); startActivity(intent); } } catch (NullPointerException e) { Utils.showToast(this, "Registration Error"); } finally { mProgressDialog.dismiss(); } mProgressDialog.dismiss(); int projectId = mSharedPrefs.getInt("PROJECT_ID", 0); if (projectId == 0) { Intent intent = new Intent(this, ShowProjectsActivity.class); startActivity(intent); } finish(); } catch (JSONException e) { if (Utils.debug) Log.e(TAG, e.toString()); } break; } }
From source file:org.hfoss.posit.android.sync.Communicator.java
/** * Gets the unique IMEI code for the phone used for identification * The phone should have proper permissions (READ_PHONE_STATE) to be able to get this data. *//* w ww.ja v a2 s. c o m*/ public static String getIMEI(Context mContext) { TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); return tm.getDeviceId(); }
From source file:org.hfoss.posit.android.RegisterActivity.java
/** * Handle all button clicks. There are two main buttons that appear on the View * when the Activity is started. When one of those buttons is clicked, a new * View is displayed with one or more additional buttons. *///from w ww. jav a2 s. c o m public void onClick(View v) { if (!Utils.isNetworkAvailable(this)) { Utils.showToast(this, "There's a problem. To register you must be on a network."); return; } Intent intent; switch (v.getId()) { // Register phone for an existing account case R.id.register: mAction = RegisterActivity.REGISTER_USER; createNewUserAccount(); break; // Create a new user account case R.id.login: mAction = RegisterActivity.REGISTER_PHONE; registerExistingAccount(); break; // Register the phone from the phone by providing valid email and password case R.id.registerDeviceButton: String password = (((TextView) findViewById(R.id.password)).getText()).toString(); String email = (((TextView) findViewById(R.id.email)).getText()).toString(); if (password.equals("") || email.equals("")) { Utils.showToast(this, "Please fill in all the fields"); break; } EmailValidator emailValidator = EmailValidator.getInstance(); if (emailValidator.isValid(email) != true) { Utils.showToast(this, "Please enter a valid address"); break; } loginUser(email, password); break; // Register the phone by reading a barcode on the server's website (Settings > Register) case R.id.registerUsingBarcodeButton: if (!isIntentAvailable(this, "com.google.zxing.client.android.SCAN")) { Utils.showToast(this, "Please install the Zxing Barcode Scanner from the Market"); break; } intent = new Intent("com.google.zxing.client.android.SCAN"); try { startActivityForResult(intent, LOGIN_BY_BARCODE_READER); } catch (ActivityNotFoundException e) { if (Utils.debug) Log.i(TAG, e.toString()); } break; // User clicks the "Login" button in the Create User View case (R.id.submitInfo): password = (((TextView) findViewById(R.id.password)).getText()).toString(); String check = (((TextView) findViewById(R.id.passCheck)).getText()).toString(); email = (((TextView) findViewById(R.id.email)).getText()).toString(); String lastname = (((TextView) findViewById(R.id.lastName)).getText()).toString(); String firstname = (((TextView) findViewById(R.id.firstName)).getText()).toString(); if (password.equals("") || check.equals("") || lastname.equals("") || firstname.equals("") || email.equals("")) { Utils.showToast(this, "Please fill in all the fields"); break; } EmailValidator emV = EmailValidator.getInstance(); if (emV.isValid(email) != true) { Utils.showToast(this, "Please enter a valid email address"); break; } if (!check.equals(password)) { Utils.showToast(this, "Your passwords do not match"); break; } TelephonyManager manager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); String imei = manager.getDeviceId(); Communicator com = new Communicator(this); String server = mSharedPrefs.getString("SERVER_ADDRESS", getString(R.string.defaultServer)); String result = com.registerUser(server, firstname, lastname, email, password, check, imei); Log.i(TAG, "RegisterUser result = " + result); if (result != null) { String[] message = result.split(":"); if (message.length != 2) { Utils.showToast(this, "Error: " + result); break; } // A new account has successfully been created. if (message[0].equals("" + Constants.AUTHN_OK)) { Editor editor = mSharedPrefs.edit(); editor.putString("EMAIL", email); editor.commit(); // The user logs in to register the device. loginUser(email, password); } else { Utils.showToast(this, message[1]); } break; } mProgressDialog.dismiss(); } }
From source file:org.hfoss.posit.android.sync.Communicator.java
/** * Returns a list of guIds for server finds that need syncing. * //from w w w.java 2 s . c o m * @return */ public static String getServerFindsNeedingSync(Context context, String authKey) { String response = ""; String url = ""; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String server = prefs.getString(SERVER_PREF, ""); int projectId = prefs.getInt(PROJECT_PREF, 0); TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String imei = telephonyManager.getDeviceId(); url = server + "/api/getDeltaFindsIds?authKey=" + authKey + "&imei=" + imei + "&projectId=" + projectId; Log.i(TAG, "getDeltaFindsIds URL=" + url); try { response = doHTTPGET(url); } catch (Exception e) { Log.i(TAG, e.getMessage()); } Log.i(TAG, "serverFindsNeedingSync = " + response); return response; }
From source file:org.hfoss.posit.android.sync.Communicator.java
public static boolean recordSync(Context context, String authKey) { // Record the synchronization in the server's sync_history table SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String server = prefs.getString(SERVER_PREF, ""); int projectId = prefs.getInt(context.getString(R.string.projectPref), 0); TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String imei = telephonyManager.getDeviceId(); String url = server + "/api/recordSync?authKey=" + authKey + "&imei=" + imei + "&projectId=" + projectId; Log.i(TAG, "recordSync URL=" + url); String responseString = ""; try {// www .j a v a 2 s .co m responseString = doHTTPGET(url); } catch (Exception e) { Log.i(TAG, e.getMessage()); e.printStackTrace(); return false; } Log.i(TAG, "HTTPGet recordSync response = " + responseString); return true; }
From source file:com.andybotting.tubechaser.activity.StationDetail.java
/** * Upload stats//from ww w. jav a 2 s .c o m */ private void uploadStats() { if (LOGV) Log.v(TAG, "Sending Station/Line statistics"); // gather all of the device info try { TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); String device_uuid = tm.getDeviceId(); String device_id = "00000000000000000000000000000000"; if (device_uuid != null) { device_id = GenericUtil.MD5(device_uuid); } LocationManager mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Location location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); // post the data HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost("http://tubechaser.andybotting.com/stats/depart/send"); post.setHeader("Content-Type", "application/x-www-form-urlencoded"); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("device_id", device_id)); pairs.add(new BasicNameValuePair("station_id", String.valueOf(mStation.getId()))); pairs.add(new BasicNameValuePair("line_id", String.valueOf(mLine.getId()))); if (location != null) { pairs.add(new BasicNameValuePair("latitude", String.valueOf(location.getLatitude()))); pairs.add(new BasicNameValuePair("longitude", String.valueOf(location.getLongitude()))); pairs.add(new BasicNameValuePair("accuracy", String.valueOf(location.getAccuracy()))); } try { post.setEntity(new UrlEncodedFormEntity(pairs)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { HttpResponse response = client.execute(post); response.getStatusLine().getStatusCode(); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); } }