List of usage examples for android.content Context TELEPHONY_SERVICE
String TELEPHONY_SERVICE
To view the source code for android.content Context TELEPHONY_SERVICE.
Click Source Link
From source file:com.appbackr.android.tracker.Tracker.java
/** * Generates a unique ID for the device. * /*from w ww . j av a 2s .c om*/ * This function obtain the Unique ID from the phone. The Unique ID consist of * Build.BOARD + Build.BRAND + Build.CPU_ABI * + Build.DEVICE + Build.DISPLAY + Build.FINGERPRINT + Build.HOST * + Build.ID + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT * + Build.TAGS + Build.TYPE + Build.USER; * + IMEI (GSM) or MEID/ESN (CDMA) * + Android-assigned id * * The Android ID may be changed everytime the user perform Factory Reset * I heard that IMEI values might not be unique because phone factory * might reuse IMEI values to cut cost. * * While the ID might be different from the same device, but resetting of the * Android phone should not occur that often. The values should be close * enough. * * @param c android application contact * @return unique ID as md5 hash generated of available parameters from device and cell phone service provider */ private static String getUDID(Context c) { // Get some of the hardware information String buildParams = Build.BOARD + Build.BRAND + Build.CPU_ABI + Build.DEVICE + Build.DISPLAY + Build.FINGERPRINT + Build.HOST + Build.ID + Build.MANUFACTURER + Build.MODEL + Build.PRODUCT + Build.TAGS + Build.TYPE + Build.USER; // Requires READ_PHONE_STATE TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); // gets the imei (GSM) or MEID/ESN (CDMA) String imei = tm.getDeviceId(); // gets the android-assigned id String androidId = Secure.getString(c.getContentResolver(), Secure.ANDROID_ID); // concatenate the string String fullHash = buildParams.toString() + imei + androidId; return md5(fullHash); }
From source file:com.nextgis.metroaccess.MetaDownloader.java
static boolean IsNetworkAvailible(Context c) { ConnectivityManager cm = (ConnectivityManager) c.getSystemService(Context.CONNECTIVITY_SERVICE); TelephonyManager tm = (TelephonyManager) c.getSystemService(Context.TELEPHONY_SERVICE); NetworkInfo info = cm.getActiveNetworkInfo(); if (info != null) { int netType = info.getType(); if (netType == ConnectivityManager.TYPE_WIFI) { return info.isConnected(); } else if (netType == ConnectivityManager.TYPE_MOBILE && !tm.isNetworkRoaming()) { return info.isConnected(); }//from www .j a v a2 s . c o m } return false; }
From source file:com.code4bones.utils.HttpUtils.java
/** * A helper method to send or retrieve data through HTTP protocol. * * @param token The token to identify the sending progress. * @param url The URL used in a GET request. Null when the method is * HTTP_POST_METHOD.//from w ww . ja v a 2 s .c o m * @param pdu The data to be POST. Null when the method is HTTP_GET_METHOD. * @param method HTTP_POST_METHOD or HTTP_GET_METHOD. * @return A byte array which contains the response data. * If an HTTP error code is returned, an IOException will be thrown. * @throws IOException if any error occurred on network interface or * an HTTP error code(>=400) returned from the server. */ public static byte[] httpConnection(Context context, long token, String url, byte[] pdu, int method, boolean isProxySet, String proxyHost, int proxyPort) throws IOException { if (url == null) { throw new IllegalArgumentException("URL must not be null."); } NetLog.v("httpConnection: params list"); NetLog.v("\ttoken\t\t= " + token); NetLog.v("\turl\t\t= " + url); NetLog.v("\tmethod\t\t= " + ((method == HTTP_POST_METHOD) ? "POST" : ((method == HTTP_GET_METHOD) ? "GET" : "UNKNOWN"))); NetLog.v("\tisProxySet\t= " + isProxySet); NetLog.v("\tproxyHost\t= " + proxyHost); NetLog.v("\tproxyPort\t= " + proxyPort); //Log.v(TAG, "\tpdu\t\t= " + Arrays.toString(pdu)); AndroidHttpClient client = null; try { // Make sure to use a proxy which supports CONNECT. URI hostUrl = new URI(url); HttpHost target = new HttpHost(hostUrl.getHost(), hostUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME); client = createHttpClient(context); HttpRequest req = null; switch (method) { case HTTP_POST_METHOD: ProgressCallbackEntity entity = new ProgressCallbackEntity(context, token, pdu); // Set request content type. entity.setContentType("application/vnd.wap.mms-message"); HttpPost post = new HttpPost(url); post.setEntity(entity); req = post; break; case HTTP_GET_METHOD: req = new HttpGet(url); break; default: Log.e(TAG, "Unknown HTTP method: " + method + ". Must be one of POST[" + HTTP_POST_METHOD + "] or GET[" + HTTP_GET_METHOD + "]."); return null; } // Set route parameters for the request. HttpParams params = client.getParams(); if (isProxySet) { ConnRouteParams.setDefaultProxy(params, new HttpHost(proxyHost, proxyPort)); } req.setParams(params); // Set necessary HTTP headers for MMS transmission. req.addHeader(HDR_KEY_ACCEPT, HDR_VALUE_ACCEPT); { //TODO: MmsConfig.getUaProfTagName(); String xWapProfileTagName = "x-wap-profile";//MmsConfig.getUaProfTagName(); String xWapProfileUrl = "mms.beeline.ru"; //MmsConfig.getUaProfUrl(); if (xWapProfileUrl != null) { NetLog.v("[HttpUtils] httpConn: xWapProfUrl=" + xWapProfileUrl); } req.addHeader(xWapProfileTagName, xWapProfileUrl); } // Extra http parameters. Split by '|' to get a list of value pairs. // Separate each pair by the first occurrence of ':' to obtain a name and // value. Replace the occurrence of the string returned by // MmsConfig.getHttpParamsLine1Key() with the users telephone number inside // the value. //TODO: MmsConfig.getHttpParams(); String extraHttpParams = null; //MmsConfig.getHttpParams(); if (extraHttpParams != null) { String line1Number = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)) .getLine1Number(); String line1Key = "key"; //MmsConfig.getHttpParamsLine1Key(); String paramList[] = extraHttpParams.split("\\|"); for (String paramPair : paramList) { String splitPair[] = paramPair.split(":", 2); if (splitPair.length == 2) { String name = splitPair[0].trim(); String value = splitPair[1].trim(); if (line1Key != null) { value = value.replace(line1Key, line1Number); } if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(value)) { req.addHeader(name, value); } } } } req.addHeader(HDR_KEY_ACCEPT_LANGUAGE, HDR_VALUE_ACCEPT_LANGUAGE); HttpResponse response = client.execute(target, req); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) { // HTTP 200 is success. throw new IOException("HTTP error: " + status.getReasonPhrase()); } HttpEntity entity = response.getEntity(); byte[] body = null; if (entity != null) { try { if (entity.getContentLength() > 0) { body = new byte[(int) entity.getContentLength()]; DataInputStream dis = new DataInputStream(entity.getContent()); try { dis.readFully(body); } finally { try { dis.close(); } catch (IOException e) { Log.e(TAG, "Error closing input stream: " + e.getMessage()); } } } if (entity.isChunked()) { Log.v(TAG, "httpConnection: transfer encoding is chunked"); //TODO: MmsConfig.getMaxMessageSize(); int bytesTobeRead = 4096; //MmsConfig.getMaxMessageSize(); byte[] tempBody = new byte[bytesTobeRead]; DataInputStream dis = new DataInputStream(entity.getContent()); try { int bytesRead = 0; int offset = 0; boolean readError = false; do { try { bytesRead = dis.read(tempBody, offset, bytesTobeRead); } catch (IOException e) { readError = true; Log.e(TAG, "httpConnection: error reading input stream" + e.getMessage()); break; } if (bytesRead > 0) { bytesTobeRead -= bytesRead; offset += bytesRead; } } while (bytesRead >= 0 && bytesTobeRead > 0); if (bytesRead == -1 && offset > 0 && !readError) { // offset is same as total number of bytes read // bytesRead will be -1 if the data was read till the eof body = new byte[offset]; System.arraycopy(tempBody, 0, body, 0, offset); Log.v(TAG, "httpConnection: Chunked response length [" + Integer.toString(offset) + "]"); } else { Log.e(TAG, "httpConnection: Response entity too large or empty"); } } finally { try { dis.close(); } catch (IOException e) { Log.e(TAG, "Error closing input stream: " + e.getMessage()); } } } } finally { if (entity != null) { entity.consumeContent(); } } } return body; } catch (URISyntaxException e) { handleHttpConnectionException(e, url); } catch (IllegalStateException e) { handleHttpConnectionException(e, url); } catch (IllegalArgumentException e) { handleHttpConnectionException(e, url); } catch (SocketException e) { handleHttpConnectionException(e, url); } catch (Exception e) { handleHttpConnectionException(e, url); } finally { if (client != null) { client.close(); } } return null; }
From source file:org.ednovo.goorusearchwidget.ResourcePlayer.java
@Override protected void onStart() { super.onStart(); TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); imeicode = tm.getDeviceId();/*ww w . ja v a 2 s . c o m*/ new httppoststart().execute(); start_time = System.currentTimeMillis(); if (flag_isPlayerTransition) { flag_isPlayerTransition = false; resourceType = ""; resourceGooruId = ""; } Log.i("onStartSearchRes", "onStart"); }
From source file:com.google.android.mms.transaction.HttpUtils.java
/** * A helper method to send or retrieve data through HTTP protocol. * * @param token The token to identify the sending progress. * @param url The URL used in a GET request. Null when the method is * HTTP_POST_METHOD./* w w w . j a v a 2 s.c om*/ * @param pdu The data to be POST. Null when the method is HTTP_GET_METHOD. * @param method HTTP_POST_METHOD or HTTP_GET_METHOD. * @return A byte array which contains the response data. * If an HTTP error code is returned, an IOException will be thrown. * @throws IOException if any error occurred on network interface or * an HTTP error code(>=400) returned from the server. */ public static byte[] httpConnection(Context context, long token, String url, byte[] pdu, int method, boolean isProxySet, String proxyHost, int proxyPort) throws IOException { if (url == null) { throw new IllegalArgumentException("URL must not be null."); } if (LOCAL_LOGV) { Log.v(TAG, "httpConnection: params list"); Log.v(TAG, "\ttoken\t\t= " + token); Log.v(TAG, "\turl\t\t= " + url); Log.v(TAG, "\tmethod\t\t= " + ((method == HTTP_POST_METHOD) ? "POST" : ((method == HTTP_GET_METHOD) ? "GET" : "UNKNOWN"))); Log.v(TAG, "\tisProxySet\t= " + isProxySet); Log.v(TAG, "\tproxyHost\t= " + proxyHost); Log.v(TAG, "\tproxyPort\t= " + proxyPort); // TODO Print out binary data more readable. //Log.v(TAG, "\tpdu\t\t= " + Arrays.toString(pdu)); } AndroidHttpClient client = null; try { // Make sure to use a proxy which supports CONNECT. URI hostUrl = new URI(url); HttpHost target = new HttpHost(hostUrl.getHost(), hostUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME); client = createHttpClient(context); HttpRequest req = null; switch (method) { case HTTP_POST_METHOD: ProgressCallbackEntity entity = new ProgressCallbackEntity(context, token, pdu); // Set request content type. entity.setContentType("application/vnd.wap.mms-message"); HttpPost post = new HttpPost(url); post.setEntity(entity); req = post; break; case HTTP_GET_METHOD: req = new HttpGet(url); break; default: Log.e(TAG, "Unknown HTTP method: " + method + ". Must be one of POST[" + HTTP_POST_METHOD + "] or GET[" + HTTP_GET_METHOD + "]."); return null; } // Set route parameters for the request. HttpParams params = client.getParams(); if (isProxySet) { ConnRouteParams.setDefaultProxy(params, new HttpHost(proxyHost, proxyPort)); } req.setParams(params); // Set necessary HTTP headers for MMS transmission. req.addHeader(HDR_KEY_ACCEPT, HDR_VALUE_ACCEPT); { String xWapProfileTagName = MmsConfig.getUaProfTagName(); String xWapProfileUrl = MmsConfig.getUaProfUrl(); if (xWapProfileUrl != null) { if (Log.isLoggable(LogTag.TRANSACTION, Log.VERBOSE)) { Log.d(LogTag.TRANSACTION, "[HttpUtils] httpConn: xWapProfUrl=" + xWapProfileUrl); } req.addHeader(xWapProfileTagName, xWapProfileUrl); } } // Extra http parameters. Split by '|' to get a list of value pairs. // Separate each pair by the first occurrence of ':' to obtain a name and // value. Replace the occurrence of the string returned by // MmsConfig.getHttpParamsLine1Key() with the users telephone number inside // the value. String extraHttpParams = MmsConfig.getHttpParams(); if (extraHttpParams != null) { String line1Number = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)) .getLine1Number(); String line1Key = MmsConfig.getHttpParamsLine1Key(); String paramList[] = extraHttpParams.split("\\|"); for (String paramPair : paramList) { String splitPair[] = paramPair.split(":", 2); if (splitPair.length == 2) { String name = splitPair[0].trim(); String value = splitPair[1].trim(); if (line1Key != null) { value = value.replace(line1Key, line1Number); } if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(value)) { req.addHeader(name, value); } } } } req.addHeader(HDR_KEY_ACCEPT_LANGUAGE, HDR_VALUE_ACCEPT_LANGUAGE); HttpResponse response = client.execute(target, req); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) { // HTTP 200 is success. throw new IOException("HTTP error: " + status.getReasonPhrase()); } HttpEntity entity = response.getEntity(); byte[] body = null; if (entity != null) { try { if (entity.getContentLength() > 0) { body = new byte[(int) entity.getContentLength()]; DataInputStream dis = new DataInputStream(entity.getContent()); try { dis.readFully(body); } finally { try { dis.close(); } catch (IOException e) { Log.e(TAG, "Error closing input stream: " + e.getMessage()); } } } } finally { if (entity != null) { entity.consumeContent(); } } } return body; } catch (URISyntaxException e) { handleHttpConnectionException(e, url); } catch (IllegalStateException e) { handleHttpConnectionException(e, url); } catch (IllegalArgumentException e) { handleHttpConnectionException(e, url); } catch (SocketException e) { handleHttpConnectionException(e, url); } catch (Exception e) { handleHttpConnectionException(e, url); } finally { if (client != null) { client.close(); } } return null; }
From source file:ru.ivanovpv.gorets.psm.mms.transaction.HttpUtils.java
/** * A helper method to send or retrieve data through HTTP protocol. * * @param token The token to identify the sending progress. * @param url The URL used in a GET request. Null when the method is * HTTP_POST_METHOD.//w ww . ja va 2s . c om * @param pdu The data to be POST. Null when the method is HTTP_GET_METHOD. * @param method HTTP_POST_METHOD or HTTP_GET_METHOD. * @return A byte array which contains the response data. * If an HTTP error code is returned, an IOException will be thrown. * @throws IOException if any error occurred on network interface or * an HTTP error code(>=400) returned from the server. */ public static byte[] httpConnection(Context context, long token, String url, byte[] pdu, int method, boolean isProxySet, String proxyHost, int proxyPort) throws IOException { if (url == null) { throw new IllegalArgumentException("URL must not be null."); } if (DEBUG) { Log.v(TAG, "httpConnection: params list"); Log.v(TAG, "\ttoken\t\t= " + token); Log.v(TAG, "\turl\t\t= " + url); Log.v(TAG, "\tmethod\t\t= " + ((method == HTTP_POST_METHOD) ? "POST" : ((method == HTTP_GET_METHOD) ? "GET" : "UNKNOWN"))); Log.v(TAG, "\tisProxySet\t= " + isProxySet); Log.v(TAG, "\tproxyHost\t= " + proxyHost); Log.v(TAG, "\tproxyPort\t= " + proxyPort); // TODO Print out binary data more readable. //Log.v(TAG, "\tpdu\t\t= " + Arrays.toString(pdu)); } AndroidHttpClient client = null; try { // Make sure to use a proxy which supports CONNECT. URI hostUrl = new URI(url); HttpHost target = new HttpHost(hostUrl.getHost(), hostUrl.getPort(), HttpHost.DEFAULT_SCHEME_NAME); client = createHttpClient(context); HttpRequest req = null; switch (method) { case HTTP_POST_METHOD: ProgressCallbackEntity entity = new ProgressCallbackEntity(context, token, pdu); // Set request content type. entity.setContentType("application/vnd.wap.mms-message"); HttpPost post = new HttpPost(url); post.setEntity(entity); req = post; break; case HTTP_GET_METHOD: req = new HttpGet(url); break; default: Log.e(TAG, "Unknown HTTP method: " + method + ". Must be one of POST[" + HTTP_POST_METHOD + "] or GET[" + HTTP_GET_METHOD + "]."); return null; } // Set route parameters for the request. HttpParams params = client.getParams(); if (isProxySet) { ConnRouteParams.setDefaultProxy(params, new HttpHost(proxyHost, proxyPort)); } req.setParams(params); // Set necessary HTTP headers for MMS transmission. req.addHeader(HDR_KEY_ACCEPT, HDR_VALUE_ACCEPT); { String xWapProfileTagName = MmsConfig.getUaProfTagName(); String xWapProfileUrl = MmsConfig.getUaProfUrl(); if (xWapProfileUrl != null) { if (DEBUG) { Log.d(TAG, "[HttpUtils] httpConn: xWapProfUrl=" + xWapProfileUrl); } req.addHeader(xWapProfileTagName, xWapProfileUrl); } } // Extra http parameters. Split by '|' to get a list of value pairs. // Separate each pair by the first occurrence of ':' to obtain a name and // value. Replace the occurrence of the string returned by // MmsConfig.getHttpParamsLine1Key() with the users telephone number inside // the value. String extraHttpParams = MmsConfig.getHttpParams(); if (extraHttpParams != null) { String line1Number = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)) .getLine1Number(); String line1Key = MmsConfig.getHttpParamsLine1Key(); String paramList[] = extraHttpParams.split("\\|"); for (String paramPair : paramList) { String splitPair[] = paramPair.split(":", 2); if (splitPair.length == 2) { String name = splitPair[0].trim(); String value = splitPair[1].trim(); if (line1Key != null) { value = value.replace(line1Key, line1Number); } if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(value)) { req.addHeader(name, value); } } } } req.addHeader(HDR_KEY_ACCEPT_LANGUAGE, HDR_VALUE_ACCEPT_LANGUAGE); HttpResponse response = client.execute(target, req); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) { // HTTP 200 is success. throw new IOException("HTTP error: " + status.getReasonPhrase()); } HttpEntity entity = response.getEntity(); byte[] body = null; if (entity != null) { try { if (entity.getContentLength() > 0) { body = new byte[(int) entity.getContentLength()]; DataInputStream dis = new DataInputStream(entity.getContent()); try { dis.readFully(body); } finally { try { dis.close(); } catch (IOException e) { Log.e(TAG, "Error closing input stream: " + e.getMessage()); } } } if (entity.isChunked()) { Log.v(TAG, "httpConnection: transfer encoding is chunked"); int bytesTobeRead = MmsConfig.getMaxMessageSize(); byte[] tempBody = new byte[bytesTobeRead]; DataInputStream dis = new DataInputStream(entity.getContent()); try { int bytesRead = 0; int offset = 0; boolean readError = false; do { try { bytesRead = dis.read(tempBody, offset, bytesTobeRead); } catch (IOException e) { readError = true; Log.e(TAG, "httpConnection: error reading input stream" + e.getMessage()); break; } if (bytesRead > 0) { bytesTobeRead -= bytesRead; offset += bytesRead; } } while (bytesRead >= 0 && bytesTobeRead > 0); if (bytesRead == -1 && offset > 0 && !readError) { // offset is same as total number of bytes read // bytesRead will be -1 if the data was read till the eof body = new byte[offset]; System.arraycopy(tempBody, 0, body, 0, offset); Log.v(TAG, "httpConnection: Chunked response length [" + Integer.toString(offset) + "]"); } else { Log.e(TAG, "httpConnection: Response entity too large or empty"); } } finally { try { dis.close(); } catch (IOException e) { Log.e(TAG, "Error closing input stream: " + e.getMessage()); } } } } finally { if (entity != null) { entity.consumeContent(); } } } return body; } catch (URISyntaxException e) { handleHttpConnectionException(e, url); } catch (IllegalStateException e) { handleHttpConnectionException(e, url); } catch (IllegalArgumentException e) { handleHttpConnectionException(e, url); } catch (SocketException e) { handleHttpConnectionException(e, url); } catch (Exception e) { handleHttpConnectionException(e, url); } finally { if (client != null) { client.close(); } } return null; }
From source file:org.ubicompforall.BusTUC.Queries.Browser.java
public String getRequestServer2(String stop, Boolean formated, double lat, double lon, int numStops, int dist, Context context) {//from w ww. j av a 2s. c o m String html_string = null; HttpGet m_get = new HttpGet(); try { stop = URLEncoder.encode(stop, "UTF-8"); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // HttpPost m_post= new // HttpPost("http://m.atb.no/xmlhttprequest.php?service=routeplannerOracle.getOracleAnswer&question="); try { final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String t_id = tm.getDeviceId(); String tmp = "TABuss"; String p_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); m_get.setURI(new URI("http://busstjener.idi.ntnu.no/MultiBRISserver/MBServlet?dest=" + stop + "&lat=" + lat + "&long=" + lon + "&type=json&nStops=" + numStops + "&maxWalkDist=" + dist + "&key=" + tmp + p_id)); HttpResponse m_response = m_client.execute(m_get); // Request html_string = httpF.requestServer(m_response); // Will fail if server is busy or down Log.v("html_string", "Returned html: " + html_string); // Long newTime = System.nanoTime() - time; // System.out.println("TIMEEEEEEEEEEEEEEEEEEEEE: " + // newTime/1000000000.0); } catch (ClientProtocolException e) { Log.v("CLIENTPROTOCOL EX", "e:" + e.toString()); } catch (IOException e) { Log.v("IO EX", "e:" + e.toString()); } catch (NullPointerException e) { Log.v("NULL", "NullPointer"); } catch (StringIndexOutOfBoundsException e) { Log.v("StringIndexOutOfBounds", "Exception"); } catch (Exception e) { e.printStackTrace(); } return html_string; }
From source file:com.wso2.mobile.mdm.api.DeviceInfo.java
/** *Returns the SIM serial number/*from w w w . j av a 2s.co m*/ */ public String getSimSerialNumber() { TelephonyManager telemamanger = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String getSimSerialNumber = telemamanger.getSimSerialNumber(); return getSimSerialNumber; }
From source file:ly.count.android.api.DeviceInfoTests.java
public void testGetCarrier() { final TelephonyManager mockTelephonyManager = mock(TelephonyManager.class); when(mockTelephonyManager.getNetworkOperatorName()).thenReturn("Verizon"); final Context mockContext = mock(Context.class); when(mockContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mockTelephonyManager); assertEquals("Verizon", DeviceInfo.getCarrier(mockContext)); }
From source file:com.marianhello.cordova.bgloc.LocationUpdateService.java
@Override public void onCreate() { super.onCreate(); Log.i(TAG, "OnCreate"); locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); alarmManager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); // Stop-detection PI stationaryAlarmPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_ALARM_ACTION), 0); registerReceiver(stationaryAlarmReceiver, new IntentFilter(STATIONARY_ALARM_ACTION)); // Stationary region PI stationaryRegionPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_REGION_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); registerReceiver(stationaryRegionReceiver, new IntentFilter(STATIONARY_REGION_ACTION)); // Stationary location monitor PI stationaryLocationPollingPI = PendingIntent.getBroadcast(this, 0, new Intent(STATIONARY_LOCATION_MONITOR_ACTION), 0); registerReceiver(stationaryLocationMonitorReceiver, new IntentFilter(STATIONARY_LOCATION_MONITOR_ACTION)); // One-shot PI (TODO currently unused) singleUpdatePI = PendingIntent.getBroadcast(this, 0, new Intent(SINGLE_LOCATION_UPDATE_ACTION), PendingIntent.FLAG_CANCEL_CURRENT); registerReceiver(singleUpdateReceiver, new IntentFilter(SINGLE_LOCATION_UPDATE_ACTION)); /////*from w w w .j ava2s. c om*/ // DISABLED // Listen to Cell-tower switches (NOTE does not operate while suspended) //telephonyManager.listen(phoneStateListener, LISTEN_CELL_LOCATION); // PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); wakeLock.acquire(); // Location criteria criteria = new Criteria(); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(true); criteria.setCostAllowed(true); }