List of usage examples for android.content Context LOCATION_SERVICE
String LOCATION_SERVICE
To view the source code for android.content Context LOCATION_SERVICE.
Click Source Link
From source file:com.updetector.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /**/*from w w w . j a v a2 s .c o m*/ * Set the views */ // Set the main layout setContentView(R.layout.activity_main); // get a handle to the console textview consoleTextView = (TextView) findViewById(R.id.console_text_id); consoleTextView.setMovementMethod(new ScrollingMovementMethod()); //setup monitoring fields environTextView = (TextView) findViewById(R.id.environment); environTextView.setText(ENVIRONMENT_PREFIX + CommonUtils.eventCodeToString(lastEnvironment)); stateTextView = (TextView) findViewById(R.id.state); //stateTextView.setText(STATE_PREFIX+"unknown"); googleStateTextView = (TextView) findViewById(R.id.google_state); googleStateTextView.setText(GOOGLE_MOBILITY_STATE_PREFIX + "unknown"); //indicatorTextView=(TextView) findViewById(R.id.indicator); //indicatorTextView.setText(INDICATOR_PREFIX); // set up the map view setupMapIfNeeded(); //set up the location client setupLocationClientIfNeeded(); /** * set up color coded map */ if (parkingBlocks == null) { parkingBlocks = ParkingBlocks.GetParkingBlocks(); showAvailabilityMap(); } mTextToSpeech = new TextToSpeech(this, this); mCalendar = Calendar.getInstance(); /* * Initialize managers */ // Instantiate an adapter to store update data from the log /* mStatusAdapter = new ArrayAdapter<Spanned>( this, R.layout.item_layout, R.id.log_text );*/ // Set the broadcast receiver intent filer mBroadcastManager = LocalBroadcastManager.getInstance(this); // Create a new Intent filter for the broadcast receiver mBroadcastFilter = new IntentFilter(Constants.ACTION_REFRESH_STATUS_LIST); mBroadcastFilter.addCategory(Constants.CATEGORY_LOCATION_SERVICES); mBroadcastFilter.addAction(Constants.BLUETOOTH_CONNECTION_UPDATE); mBroadcastFilter.addAction(Constants.GOOGLE_ACTIVITY_RECOGNITION_UPDATE); mBroadcastManager.registerReceiver(mBroadcastReceiver, mBroadcastFilter); // Get the instance of the customized notification manager mDetectionNotificationManager = DetectionNotificationManager.getInstance(this); //Get the FusionManager object mFusionManager = new FusionManager(this); // Get the ClassificationManager object mClassificationManager = ClassificationManager.getInstance(this); //TODO train classifiers if necessary if (Constants.IS_TRAINING_MODE) { int[] classifiersToBeTrained = { Constants.ACCEL_MOTION_STATE }; for (int classifier : classifiersToBeTrained) { mClassificationManager.mClassfiers.get(classifier).train(); } } //get the sensor service mSensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE); //get the accelerometer sensor mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mSensorManager.registerListener(mSensorEventListener, mAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); mAudioRecordManager = AudioRecordManager.getInstance(); // Get the WakeLockManager object mWakeLockManager = WakeLockManager.getInstance(this); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // Get the LogManager object mLogManager = LogManager.getInstance(this); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mXPSHandler = new XPS(this); mXPSHandler.setRegistrationUser(new WPSAuthentication("dbmc", "uic")); //mXPSHandler.setTiling("", 0, 0, null); /** * Initialize IODetector */ cellTowerChart = new CellTowerChart((TelephonyManager) getSystemService(TELEPHONY_SERVICE), this); magnetChart = new MagnetChart(mSensorManager, this); lightChart = new LightChart(mSensorManager, this); //new AggregatedIODetector().execute("");//Check the detection for the first time //This timer handle starts the aggregated calculation for the detection //Interval 1 seconds. Timer uiTimer = new Timer(); mIODectorHandler = new Handler(); /*uiTimer.scheduleAtFixedRate(new TimerTask() { private int walked = 0; @Override public void run() { mIODectorHandler.post(new Runnable() { @Override public void run() { if(phoneNotStill){//Check if the user is walking walked++; } else{ walked = 0; } if(aggregationFinish && walked > 3){//Check if the user has walked for at least 3 second, and the previous calculation has been finish aggregationFinish = false; walked = 0; new AggregatedIODetector().execute(""); } } }); } }, 0, 1000);*/ /** * Initialize fields other than managers */ lastAccReading = new double[3]; /** * Startup routines */ // catch the force close error Thread.setDefaultUncaughtExceptionHandler(new UnCaughtException(MainActivity.this)); /** * Start Google Activity Recognition */ mGoogleActivityDetectionRequester = new GoogleActivityRecognitionClientRequester(this); mGoogleActivityDetectionRemover = new GoogleActivityRecognitionClientRemover(this); startGoogleActivityRecognitionUpdates(null); checkGPSEnabled(); //test record sample //mAudioRecordManager.recordAudioSample("/sdcard/audio.wav"); //Test extract features from audio files //String features=AudioFeatureExtraction.extractFeatures(this, "/sdcard/bus6.wav"); //mClassificationManager.mClassfiers.get(Constants.SENSOR_MICROPHONE).classify(features); }
From source file:com.openatk.fieldnotebook.MainActivity.java
private void checkGPS() { final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { buildAlertMessageNoGps();// w w w. j a v a 2 s .c o m } }
From source file:org.planetmono.dcuploader.ActivityUploader.java
@Override public void onDestroy() { super.onDestroy(); Log.d(Application.TAG, "stopping activity."); /* stop location query when going out */ if (locationEnabled) { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); lm.removeUpdates(locationTracker); }/*from w w w.j a v a2 s.c o m*/ for (String path : tempFiles) new File(path).delete(); tempFiles.clear(); }
From source file:com.lewa.crazychapter11.MainActivity.java
public boolean hasGPSDevice(Context context) { final LocationManager mgr = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (mgr == null) return false; final List<String> providers = mgr.getAllProviders(); if (providers == null) return false; Log.i("algerheGps", "System hasGps=" + providers.contains(LocationManager.GPS_PROVIDER)); return providers.contains(LocationManager.GPS_PROVIDER); }
From source file:org.planetmono.dcuploader.ActivityUploader.java
@Override public void onResume() { super.onResume(); /* resume location query */ if (locationEnabled) { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationTracker); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationTracker); }// w w w . ja v a2 s. co m }
From source file:com.vonglasow.michael.satstat.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); defaultUEH = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { Context c = getApplicationContext(); File dumpDir = c.getExternalFilesDir(null); File dumpFile = new File(dumpDir, "satstat-" + System.currentTimeMillis() + ".log"); PrintStream s;/*from w w w . j a v a2 s. c o m*/ try { InputStream buildInStream = getResources().openRawResource(R.raw.build); s = new PrintStream(dumpFile); s.append("SatStat build: "); int i; try { i = buildInStream.read(); while (i != -1) { s.write(i); i = buildInStream.read(); } buildInStream.close(); } catch (IOException e1) { e1.printStackTrace(); } s.append("\n\n"); e.printStackTrace(s); s.flush(); s.close(); } catch (FileNotFoundException e2) { e2.printStackTrace(); } defaultUEH.uncaughtException(t, e); } }); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mSharedPreferences.registerOnSharedPreferenceChangeListener(this); final ActionBar actionBar = getActionBar(); setContentView(R.layout.activity_main); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); // Find out default screen orientation Configuration config = getResources().getConfiguration(); WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); int rot = wm.getDefaultDisplay().getRotation(); isWideScreen = (config.orientation == Configuration.ORIENTATION_LANDSCAPE && (rot == Surface.ROTATION_0 || rot == Surface.ROTATION_180) || config.orientation == Configuration.ORIENTATION_PORTRAIT && (rot == Surface.ROTATION_90 || rot == Surface.ROTATION_270)); Log.d("MainActivity", "isWideScreen=" + Boolean.toString(isWideScreen)); // compact action bar int dpX = (int) (this.getResources().getDisplayMetrics().widthPixels / this.getResources().getDisplayMetrics().density); /* * This is a crude way to ensure a one-line action bar with tabs * (not a drop-down list) and home (incon) and title only if there * is space, depending on screen width: * divide screen in units of 64 dp * each tab requires 1 unit, home and menu require slightly less, * title takes up approx. 2.5 units in portrait, * home and title are about 2 units wide in landscape */ if (dpX < 192) { // just enough space for drop-down list and menu actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); } else if (dpX < 320) { // not enough space for four tabs, but home will fit next to list actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(false); } else if (dpX < 384) { // just enough space for four tabs actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayShowTitleEnabled(false); } else if ((dpX < 448) || ((config.orientation == Configuration.ORIENTATION_PORTRAIT) && (dpX < 544))) { // space for four tabs and home, but not title actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(false); } else { // ample space for home, title and all four tabs actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayShowTitleEnabled(true); } setEmbeddedTabs(actionBar, true); providerLocations = new HashMap<String, Location>(); mAvailableProviderStyles = new ArrayList<String>(Arrays.asList(LOCATION_PROVIDER_STYLES)); providerStyles = new HashMap<String, String>(); providerAppliedStyles = new HashMap<String, String>(); providerInvalidationHandler = new Handler(); providerInvalidators = new HashMap<String, Runnable>(); // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); mViewPager.setOnPageChangeListener(this); // Add tabs, specifying the tab's text and TabListener for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { actionBar.addTab(actionBar.newTab() //.setText(mSectionsPagerAdapter.getPageTitle(i)) .setIcon(mSectionsPagerAdapter.getPageIcon(i)).setTabListener(this)); } // This is needed by the mapsforge library. AndroidGraphicFactory.createInstance(this.getApplication()); // Get system services for event delivery mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mOrSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); mAccSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mGyroSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mMagSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mLightSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); mProximitySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mPressureSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); mHumiditySensor = mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); mTempSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); mConnectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); mAccSensorRes = getSensorDecimals(mAccSensor, mAccSensorRes); mGyroSensorRes = getSensorDecimals(mGyroSensor, mGyroSensorRes); mMagSensorRes = getSensorDecimals(mMagSensor, mMagSensorRes); mLightSensorRes = getSensorDecimals(mLightSensor, mLightSensorRes); mProximitySensorRes = getSensorDecimals(mProximitySensor, mProximitySensorRes); mPressureSensorRes = getSensorDecimals(mPressureSensor, mPressureSensorRes); mHumiditySensorRes = getSensorDecimals(mHumiditySensor, mHumiditySensorRes); mTempSensorRes = getSensorDecimals(mTempSensor, mTempSensorRes); networkTimehandler = new Handler(); networkTimeRunnable = new Runnable() { @Override public void run() { int newNetworkType = mTelephonyManager.getNetworkType(); if (getNetworkGeneration(newNetworkType) != mLastNetworkGen) onNetworkTypeChanged(newNetworkType); else networkTimehandler.postDelayed(this, NETWORK_REFRESH_DELAY); } }; wifiTimehandler = new Handler(); wifiTimeRunnable = new Runnable() { @Override public void run() { mWifiManager.startScan(); wifiTimehandler.postDelayed(this, WIFI_REFRESH_DELAY); } }; updateLocationProviderStyles(); }
From source file:com.androzic.Androzic.java
/** * Retrieves last known location without enabling location providers. * @return Most precise last known location or null if it is not available *///from ww w. j ava2s .c om public Location getLastKnownSystemLocation() { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(true); Location l = null; for (int i = providers.size() - 1; i >= 0; i--) { l = lm.getLastKnownLocation(providers.get(i)); if (l != null) break; } return l; }
From source file:com.piusvelte.sonet.core.SonetCreatePost.java
protected void chooseAccounts() { // don't limit accounts to the widget... Cursor c = this.getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID, ACCOUNTS_QUERY, Accounts.SERVICE }, null, null, null); if (c.moveToFirst()) { int i = 0; ;/*www . ja v a 2 s. c om*/ int count = c.getCount(); final long[] accountIndexes = new long[count]; final String[] accounts = new String[count]; final boolean[] defaults = new boolean[count]; final int[] accountServices = new int[count]; while (!c.isAfterLast()) { long id = c.getLong(0); accountIndexes[i] = id; accounts[i] = c.getString(1); accountServices[i] = c.getInt(2); defaults[i++] = mAccountsService.containsKey(id); c.moveToNext(); } mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.accounts) .setMultiChoiceItems(accounts, defaults, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { final long accountId = accountIndexes[which]; mAccountsService.put(accountId, accountServices[which]); if (sLocationSupported.contains(accountServices[which])) { if (mLat == null) { LocationManager locationManager = (LocationManager) SonetCreatePost.this .getSystemService(Context.LOCATION_SERVICE); Location location = locationManager .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) { mLat = Double.toString(location.getLatitude()); mLong = Double.toString(location.getLongitude()); } } if ((mLat != null) && (mLong != null)) { dialog.cancel(); mDialog = (new AlertDialog.Builder(SonetCreatePost.this)) .setTitle(R.string.set_location) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setLocation(accountId); dialog.dismiss(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .create(); mDialog.show(); } } } else { mAccountsService.remove(accountIndexes[which]); mAccountsLocation.remove(accountIndexes[which]); mAccountsTags.remove(accountIndexes[which]); } } }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create(); mDialog.show(); } c.close(); }
From source file:com.BeatYourRecord.SubmitActivity.java
private void getVideoLocation() { this.locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_HIGH); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false);//ww w .j a v a 2 s. c o m criteria.setSpeedRequired(false); criteria.setCostAllowed(true); String provider = locationManager.getBestProvider(criteria, true); this.locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { if (location != null) { SubmitActivity.this.videoLocation = location; lat = location.getLatitude(); lng = location.getLongitude(); Log.d(LOG_TAG, "lat=" + lat); Log.d(LOG_TAG, "lng=" + lng); TextView locationText = (TextView) findViewById(R.id.locationLabel); locationText.setText("Geo Location: " + String.format("lat=%.2f lng=%.2f", lat, lng)); locationManager.removeUpdates(this); } else { Log.d(LOG_TAG, "location is null"); } } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }; if (provider != null) { locationManager.requestLocationUpdates(provider, 2000, 10, locationListener); } }
From source file:com.shafiq.myfeedle.core.MyfeedleCreatePost.java
protected void chooseAccounts() { // don't limit accounts to the widget... Cursor c = this.getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID, ACCOUNTS_QUERY, Accounts.SERVICE }, null, null, null); if (c.moveToFirst()) { int i = 0; ;/*from ww w . j a v a 2 s . c o m*/ int count = c.getCount(); final long[] accountIndexes = new long[count]; final String[] accounts = new String[count]; final boolean[] defaults = new boolean[count]; final int[] accountServices = new int[count]; while (!c.isAfterLast()) { long id = c.getLong(0); accountIndexes[i] = id; accounts[i] = c.getString(1); accountServices[i] = c.getInt(2); defaults[i++] = mAccountsService.containsKey(id); c.moveToNext(); } mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.accounts) .setMultiChoiceItems(accounts, defaults, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { if (isChecked) { final long accountId = accountIndexes[which]; mAccountsService.put(accountId, accountServices[which]); if (sLocationSupported.contains(accountServices[which])) { if (mLat == null) { LocationManager locationManager = (LocationManager) MyfeedleCreatePost.this .getSystemService(Context.LOCATION_SERVICE); Location location = locationManager .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (location != null) { mLat = Double.toString(location.getLatitude()); mLong = Double.toString(location.getLongitude()); } } if ((mLat != null) && (mLong != null)) { dialog.cancel(); mDialog = (new AlertDialog.Builder(MyfeedleCreatePost.this)) .setTitle(R.string.set_location) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setLocation(accountId); dialog.dismiss(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .create(); mDialog.show(); } } } else { mAccountsService.remove(accountIndexes[which]); mAccountsLocation.remove(accountIndexes[which]); mAccountsTags.remove(accountIndexes[which]); } } }).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create(); mDialog.show(); } c.close(); }