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.tritop.androsense2.fragments.GpsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); mSensorManager = ((AndrosensApp) getActivity().getApplication()).getSensorManager(); defaultAccel = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); defaultMag = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mGpsListAdapter = new SimpleAdapter(getActivity(), itemListGps, R.layout.gpsfragment_sat_item, boundRows, boundViews);//from w w w . jav a 2 s. c o m mGlonassListAdapter = new SimpleAdapter(getActivity(), itemListGlonass, R.layout.gpsfragment_sat_item, boundRows, boundViews); setupViewBinders(mGpsListAdapter, R.drawable.shape_satitem_background_nofix, R.drawable.shape_satitem_background_fix); setupViewBinders(mGlonassListAdapter, R.drawable.shape_satitem_background_glonass_nofix, R.drawable.shape_satitem_background_glonass_fix); display = getActivity().getWindowManager().getDefaultDisplay(); return inflater.inflate(R.layout.gpsfragment_layout, container, false); }
From source file:com.tagaugmentedreality.utilties.Utilities.java
public static boolean locationProviderStatus(Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) && locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { return true; } // end if//from w ww . ja v a2 s . co m else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { return true; } // end if else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { return true; } // end else if else { return false; } // end else }
From source file:com.mruddy.devdataviewer.SensorFragment.java
/** * @see android.support.v4.app.Fragment#onResume() *//*w w w . ja v a 2 s . c om*/ @Override public void onResume() { super.onResume(); this.accelerometerTextView = (TextView) this.getActivity().findViewById(R.id.textViewAccelerometer); this.gpsTextView = (TextView) this.getActivity().findViewById(R.id.textViewGPS); this.sensorManager = (SensorManager) this.getActivity().getSystemService(Context.SENSOR_SERVICE); final Sensor accelerometerSensor = this.sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); if (null != accelerometerSensor) { this.accelerometerTextView.setText("waiting for data..."); this.sensorManager.registerListener(this, accelerometerSensor, SensorManager.SENSOR_DELAY_NORMAL); } else { this.accelerometerTextView.setText("accelerometer not found"); } this.locationManager = (LocationManager) this.getActivity().getSystemService(Context.LOCATION_SERVICE); this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); }
From source file:com.jmstudios.redmoon.preference.LocationPreference.java
public void searchLocation(boolean explicitRequest) { if (mIsSearchingLocation) mIsSearchExplicit = explicitRequest || mIsSearchExplicit; else/* ww w .ja v a2 s . co m*/ mIsSearchExplicit = explicitRequest; if (!mIsSearchingLocation) { if (DEBUG) Log.i(TAG, explicitRequest ? "Searching location on explicit request" : "Searching location automatically"); mIsSearchingLocation = true; LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { LocationListener listener = new LocationUpdateListener(mContext, this); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, listener); } else { handleLocationSearchFailed(); } } if (mIsSearchExplicit && mIsSearchingLocation) { setSummary(mContext.getString(R.string.searching_location)); } }
From source file:com.example.isse.weatherapp.ui.WeatherListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_weather_list); //setup the toolbar Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//from ww w . j av a 2 s . c o m toolbar.setTitle(getTitle()); mContext = this; if (findViewById(R.id.weather_detail_container) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-w900dp). // If this view is present, then the // activity should be in two-pane mode. mTwoPane = true; } locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); //Calling initLoader when the Loader has already been created // (this typically happens after configuration changes, for example) // tells the LoaderManager to deliver the Loader's most recent data to onLoadFinished immediately. getLoaderManager().initLoader(CURSOR_LOADER_ID, null, this); //get the fragment manager and pass it later to the recyclerview adapter fragmentManager = getSupportFragmentManager(); View emptyView = findViewById(R.id.recyclerview_weather_empty); mCursorAdapter = new MyWeatherCursorAdapter(this, mCursor, emptyView, mTwoPane, fragmentManager); recyclerView = (RecyclerView) findViewById(R.id.weather_list); if (recyclerView != null) { setupRecyclerView(recyclerView); } if (checkPermission()) { requestPermission(); } //content observer myObserver = new MyLocationObserver(new Handler()); }
From source file:com.platform.GeoLocationManager.java
public void startGeoSocket(Session sess) { session = sess;//w w w .ja va 2 s . com final MainActivity app = MainActivity.app; if (app == null) return; final LocationManager locationManager = (LocationManager) app.getSystemService(Context.LOCATION_SERVICE); app.runOnUiThread(new Runnable() { @Override public void run() { if (ActivityCompat.checkSelfPermission(app, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(app, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { RuntimeException ex = new RuntimeException("startGeoSocket, can't happen"); Log.e(TAG, "run: startGeoSocket, can't happen"); FirebaseCrash.report(ex); return; } locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, socketLocationListener); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, socketLocationListener); } }); }
From source file:com.example.get_location.Get_location.java
/** * This sample demonstrates how to incorporate location based services in your app and * process location updates. The app also shows how to convert lat/long coordinates to * human-readable addresses./*ww w . j a v a 2s . c o m*/ */ @SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_getlocation); // Restore apps state (if exists) after rotation. if (savedInstanceState != null) { mUseFine = savedInstanceState.getBoolean(KEY_FINE); mUseBoth = savedInstanceState.getBoolean(KEY_BOTH); } else { mUseFine = false; mUseBoth = false; } mLatLng = (TextView) findViewById(R.id.latlng); mAddress = (TextView) findViewById(R.id.address); // Receive location updates from the fine location provider (gps) only. mFineProviderButton = (Button) findViewById(R.id.provider_fine); // Receive location updates from both the fine (gps) and coarse (network) location // providers. mBothProviderButton = (Button) findViewById(R.id.provider_both); // The isPresent() helper method is only available on Gingerbread or above. mGeocoderAvailable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && Geocoder.isPresent(); // Handler for updating text fields on the UI like the lat/long and address. mHandler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case UPDATE_ADDRESS: mAddress.setText((String) msg.obj); break; case UPDATE_LATLNG: mLatLng.setText((String) msg.obj); break; } } }; // Get a reference to the LocationManager object. mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); }
From source file:ca.mudar.mtlaucasou.BaseListFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mActivityHelper = ActivityHelper.createInstance(getActivity()); mAppHelper = ((AppHelper) getActivity().getApplicationContext()); locationManager = (LocationManager) getSupportActivity().getSystemService(Context.LOCATION_SERVICE); locationListener = new MyLocationListener(); criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); SharedPreferences prefs = getSupportActivity().getSharedPreferences(Const.APP_PREFS_NAME, Context.MODE_PRIVATE); hasFollowLocationChanges = prefs.getBoolean(Const.PrefsNames.FOLLOW_LOCATION_CHANGES, false); Location myLocation = mAppHelper.getLocation(); mHandler = new NotifyingAsyncQueryHandler(getActivity().getContentResolver(), this); if (mCursor != null) { getActivity().stopManagingCursor(mCursor); mCursor = null;/*from w ww . j ava2 s. c o m*/ } setListAdapter(null); mHandler.cancelOperation(QUERY_TOKEN); /** * Update the projection alias to calculate the distance based on the * current Location. */ String mSort; if (mAppHelper.getListSort().equals(PrefsValues.LIST_SORT_DISTANCE) && myLocation != null) { mSort = PlacemarkColumns.PLACEMARK_DISTANCE + " ASC "; } else { mSort = defaultSort; } mCursor = getActivity().getContentResolver().query(mActivityHelper.getContentUri(indexSection), PLACEMARKS_SUMMARY_PROJECTION, null, null, mSort); getActivity().startManagingCursor(mCursor); mAdapter = new PlacemarksCursorAdapter(getActivity(), R.layout.fragment_list_item_placemarks, mCursor, new String[] { PlacemarkColumns.PLACEMARK_NAME, PlacemarkColumns.PLACEMARK_ADDRESS }, new int[] { R.id.placemark_name, R.id.placemark_address }, 0); setListAdapter(mAdapter); mHandler.startQuery(QUERY_TOKEN, null, mActivityHelper.getContentUri(indexSection), PLACEMARKS_SUMMARY_PROJECTION, null, null, mSort); }
From source file:chat.client.gui.ChatActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); myNum = tm.getLine1Number();/*from w ww . j av a2s .c o m*/ Bundle extras = getIntent().getExtras(); if (extras != null) { nickname = extras.getString("nickname"); } provider = LocationManager.GPS_PROVIDER; locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location location = locationManager.getLastKnownLocation(provider); locationManager.requestLocationUpdates(provider, 0, 0, new LocationListener() { @Override public void onLocationChanged(Location location) { // if (location != null) // updateWithNewLocation(location); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }); try { chatClientInterface = MicroRuntime.getAgent(nickname).getO2AInterface(ChatClientInterface.class); } catch (StaleProxyException e) { showAlertDialog(getString(R.string.msg_interface_exc), true); } catch (ControllerException e) { showAlertDialog(getString(R.string.msg_controller_exc), true); } myReceiver = new MyReceiver(); IntentFilter refreshChatFilter = new IntentFilter(); refreshChatFilter.addAction("jade.demo.chat.REFRESH_CHAT"); registerReceiver(myReceiver, refreshChatFilter); IntentFilter clearChatFilter = new IntentFilter(); clearChatFilter.addAction("jade.demo.chat.CLEAR_CHAT"); registerReceiver(myReceiver, clearChatFilter); setContentView(R.layout.chat); Button button = (Button) findViewById(R.id.button_send); button.setOnClickListener(buttonSendListener); TelephonyManager mgr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE); listener = new PhoneCallListener(); mgr.listen(listener, PhoneStateListener.LISTEN_CALL_STATE); }
From source file:com.nextgis.mobile.forms.CompassFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // reference to vibrator service vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); // vibrate or not? SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); vibrationOn = prefs.getBoolean("compass_vibration", true); if (mCurrentLocation == null) { LocationManager locationManager = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); mCurrentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (mCurrentLocation == null) { mCurrentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); }/*w w w.j av a2 s. c om*/ } mDeclination = 0; if (mCurrentLocation != null) { mDeclination = getDeclination(mCurrentLocation, System.currentTimeMillis()); } sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); sensorManager.registerListener(sensorListener, sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION), SensorManager.SENSOR_DELAY_NORMAL); getActivity().registerReceiver(compassBroadcastReceiver, new IntentFilter(ACTION_COMPASS_UPDATES)); Log.d(TAG, "CompassActivity: onCreate"); }