List of usage examples for android.location LocationListener LocationListener
LocationListener
From source file:ch.hesso.master.sweetcity.activity.report.ReportActivity.java
void updateCurrentLocation() { if (this.locationListener == null) this.locationListener = new LocationListener() { @Override// w ww .j ava2s .c o m public void onLocationChanged(Location location) { ReportActivity.this.currentLocation = location; } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }; Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(false); criteria.setHorizontalAccuracy(Criteria.ACCURACY_MEDIUM); criteria.setPowerRequirement(Criteria.NO_REQUIREMENT); criteria.setSpeedAccuracy(Criteria.NO_REQUIREMENT); criteria.setSpeedRequired(false); LocationManager locationManager = (LocationManager) ReportActivity.this.getSystemService(LOCATION_SERVICE); locationManager.requestSingleUpdate(criteria, this.locationListener, null); }
From source file:pw.dedominic.csc311_final_project.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); MAC_ADDR = mBluetoothAdapter.getAddress(); // ready GPS unit mLocationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); mLocationListener = new LocationListener() { @Override/* w w w . j a v a 2s . c o m*/ public void onLocationChanged(Location location) { PLAYER_LATITUDE = location.getLatitude(); PLAYER_LONGITUDE = location.getLongitude(); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }; mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener); if (mLocationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER)) { mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, mLocationListener); PROVIDER = LocationManager.NETWORK_PROVIDER; } else { PROVIDER = LocationManager.GPS_PROVIDER; } mHttpService.recreateGetUserNameTask(); mHttpService.getUserName(MAC_ADDR); }
From source file:semanticweb.hws14.movapp.activities.Criteria.java
private void initCriteriaView() { //Init the location stuff locMgr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); locListner = new LocationListener() { public void onLocationChanged(Location location) { useLocationData(location);/*from w w w . j a v a 2 s . c o m*/ } //standard methods public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } }; }
From source file:com.careme.apvereda.careme.AccumulatorService.java
@Override public int onStartCommand(Intent intenc, int flags, int idArranque) { SharedPreferences sharedPref = getApplicationContext().getSharedPreferences("basicData", Context.MODE_PRIVATE); String email = sharedPref.getString("email", ""); //Uncomment to use Nimbees features /*if (email.compareTo("") != 0) { try {/*from w w w. j a va 2s .c o m*/ // Initialize library calling the init method on the Nimbees Client NimbeesClient.init(this); } catch (NimbeesException e) { e.printStackTrace(); } NimbeesClient.getUserManager().register("email", new NimbeesRegistrationCallback() { @Override public void onSuccess() { /* Registration was successful! Toast.makeText(getApplicationContext(), "xito en el registro", Toast.LENGTH_LONG).show(); } @Override public void onFailure(NimbeesException failure) { /* Registration failed Toast.makeText(getApplicationContext(), "Fallo en el registro", Toast.LENGTH_LONG).show(); } }); } */ //Toast.makeText(this,"Servicio arrancado "+ idArranque, Toast.LENGTH_SHORT).show(); // Obtain a reference to the Location Manager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria crit = new Criteria(); crit.setAccuracy(Criteria.ACCURACY_FINE); crit.setPowerRequirement(Criteria.POWER_LOW); provider = locManager.getBestProvider(crit, true); // And register to obtain current location updates locListener = new LocationListener() { public void onLocationChanged(Location loc) { // Insert a new entry on History History history = new History(loc.getLatitude(), loc.getLongitude(), new Date()); db.insertHistory(history); //Uncomment to use Nimbees features /* try { sendPersonalizado(loc); } catch (Exception e) { }*/ /* Monitor makes the monitoring of the user to determine if he/she has lost */ monitor(loc); } @Override public void onStatusChanged(String provider, int stat, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }; // We want to update the current location every time the user moves MIN_DISTANCE locManager.requestLocationUpdates(provider, 0, MIN_DISTANCE, locListener); return START_STICKY; }
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 www. j ava2s . 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:org.traccar.client.ShortcutActivity.java
@SuppressWarnings("MissingPermission") private void sendAlarm() { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); String provider = PositionProvider.getProvider(preferences.getString(MainFragment.KEY_ACCURACY, "medium")); try {//from w ww . j ava2s . c o m Location location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); if (location != null) { sendAlarmLocation(location); } else { locationManager.requestSingleUpdate(provider, new LocationListener() { @Override public void onLocationChanged(Location location) { sendAlarmLocation(location); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }, Looper.myLooper()); } } catch (RuntimeException e) { Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } }
From source file:com.chalmers.schmaps.CheckInActivity.java
@Override /**//from www .j ava 2 s . c om * onCreate method for determining what the activity does on creation. * Sets the right view for the user and assigns fields. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //assigns variables used in this class assignInstances(); //if there is an provider that provides an location ->continue if (location != null) { //get the latitude latitude = (int) (location.getLatitude() * CONVERTTOGEOPOINTVALUE); //get the longitude longitude = (int) (location.getLongitude() * CONVERTTOGEOPOINTVALUE); //greates an geopoint with our location ourLocation = new GeoPoint(latitude, longitude); mapcon.animateTo(ourLocation); //zoom level mapcon.setZoom(ZOOMVALUEFOROVERVIEW); } locationListener = new LocationListener() { /** * method is called when location is changed, when onResumed() is called */ public void onLocationChanged(Location loc) { //get the latitude latitude = (int) (location.getLatitude() * CONVERTTOGEOPOINTVALUE); //get the longitude longitude = (int) (location.getLongitude() * CONVERTTOGEOPOINTVALUE); //greates an geopoint with our location ourLocation = new GeoPoint(latitude, longitude); } public void onProviderDisabled(String provider) { } public void onProviderEnabled(String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } }; connectExternalDatabase(); }
From source file:com.example.traveljoin.wikitude.AbstractArchitectCamFragmentV4.java
@SuppressLint("NewApi") @Override//from ww w. ja va2 s . c o m public void onActivityCreated(final Bundle bundle) { super.onActivityCreated(bundle); // set architectView, important for upcoming lifecycle calls this.architectView = (ArchitectView) this.getView().findViewById(getArchitectViewId()); // pass license key to architectView while creating it final ArchitectConfig config = new ArchitectConfig(this.getWikitudeSDKLicenseKey()); // forwards mandatory life-cycle-events, unfortunately there is no onPostCreate() event in fragments so we have to call it that way try { /* first mandatory life-cycle notification */ this.architectView.onCreate(config); this.architectView.onPostCreate(); } catch (RuntimeException rex) { this.architectView = null; Toast.makeText(getActivity().getApplicationContext(), "can't create Architect View", Toast.LENGTH_SHORT) .show(); Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex); } /* * this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml * If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse. * You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place. * Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } } try { // load architectView's content this.architectView.load(this.getARchitectWorldPath()); if (this.getInitialCullingDistanceMeters() != ArchitectViewHolderInterface.CULLING_DISTANCE_DEFAULT_METERS) { // set the culling distance - meaning: the maximum distance to render geo-content this.architectView.setCullingDistance(this.getInitialCullingDistanceMeters()); } } catch (IOException e) { // unexpected, if error occurs here your path is invalid e.printStackTrace(); } // listener passed over to locationProvider, any location update is handled here this.locationListener = new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(final Location location) { if (location != null) { AbstractArchitectCamFragmentV4.this.lastKnownLocaton = location; if (AbstractArchitectCamFragmentV4.this.architectView != null) { // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information) if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) { AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getAccuracy()); } else { AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.hasAccuracy() ? location.getAccuracy() : 1000); } } } } }; // set accuracy listener if implemented, you may e.g. show calibration prompt for compass using this listener this.sensorAccuracyListener = this.getSensorAccuracyListener(); // set urlListener, any calls made in JS like "document.location = 'architectsdk://foo?bar=123'" is forwarded to this listener, use this to interact between JS and native Android activity/fragment this.urlListener = this.getUrlListener(); // register valid urlListener in architectView, ensure this is set before content is loaded to not miss any event if (this.urlListener != null) { this.architectView.registerUrlListener(this.getUrlListener()); } // locationProvider used to fetch user position this.locationProvider = this.getLocationProvider(this.locationListener); }
From source file:com.spectralinsights.locar.AbstractArchitectCamFragmentV4.java
@SuppressLint("NewApi") @Override/* w ww . ja va 2 s .c o m*/ public void onActivityCreated(final Bundle bundle) { super.onActivityCreated(bundle); // set architectView, important for upcoming lifecycle calls this.architectView = (ArchitectView) this.getView().findViewById(getArchitectViewId()); // pass license key to architectView while creating it final StartupConfiguration config = new StartupConfiguration(this.getWikitudeSDKLicenseKey(), ArchitectView.getSupportedFeaturesForDevice(getActivity())); // forwards mandatory life-cycle-events, unfortunately there is no onPostCreate() event in fragments so we have to call it that way try { /* first mandatory life-cycle notification */ this.architectView.onCreate(config); this.architectView.onPostCreate(); } catch (RuntimeException rex) { this.architectView = null; Toast.makeText(getActivity().getApplicationContext(), "can't create Architect View", Toast.LENGTH_SHORT) .show(); Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex); } /* * this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml * If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse. * You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place. * Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } } try { // load architectView's content this.architectView.load(this.getARchitectWorldPath()); if (this.getInitialCullingDistanceMeters() != ArchitectViewHolderInterface.CULLING_DISTANCE_DEFAULT_METERS) { // set the culling distance - meaning: the maximum distance to render geo-content this.architectView.setCullingDistance(this.getInitialCullingDistanceMeters()); } } catch (IOException e) { // unexpected, if error occurs here your path is invalid e.printStackTrace(); } // listener passed over to locationProvider, any location update is handled here this.locationListener = new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(final Location location) { if (location != null) { AbstractArchitectCamFragmentV4.this.lastKnownLocaton = location; if (AbstractArchitectCamFragmentV4.this.architectView != null) { // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information) if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) { AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getAccuracy()); } else { AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.hasAccuracy() ? location.getAccuracy() : 1000); } } } } }; // set accuracy listener if implemented, you may e.g. show calibration prompt for compass using this listener this.sensorAccuracyListener = this.getSensorAccuracyListener(); // set urlListener, any calls made in JS like "document.location = 'architectsdk://foo?bar=123'" is forwarded to this listener, use this to interact between JS and native Android activity/fragment this.urlListener = this.getUrlListener(); // register valid urlListener in architectView, ensure this is set before content is loaded to not miss any event if (this.urlListener != null) { this.architectView.registerUrlListener(this.getUrlListener()); } // locationProvider used to fetch user position this.locationProvider = this.getLocationProvider(this.locationListener); }
From source file:com.example.user.anniefyppostcard.fragments.AbstractArchitectCamFragmentV4.java
@SuppressLint("NewApi") @Override//w w w. ja v a 2 s .c o m public void onActivityCreated(final Bundle bundle) { super.onActivityCreated(bundle); // set architectView, important for upcoming lifecycle calls this.architectView = (ArchitectView) this.getView().findViewById(getArchitectViewId()); // pass license key to architectView while creating it final StartupConfiguration config = new StartupConfiguration(this.getWikitudeSDKLicenseKey(), ArchitectView.getSupportedFeaturesForDevice(getActivity())); // forwards mandatory life-cycle-events, unfortunately there is no onPostCreate() event in fragments so we have to call it that way try { /* first mandatory life-cycle notification */ this.architectView.onCreate(config); this.architectView.onPostCreate(); } catch (RuntimeException rex) { this.architectView = null; Toast.makeText(getActivity().getApplicationContext(), "can't create Architect View", Toast.LENGTH_SHORT) .show(); Log.e(this.getClass().getName(), "Exception in ArchitectView.onCreate()", rex); } /* * this enables remote debugging of a WebView on Android 4.4+ when debugging = true in AndroidManifest.xml * If you get a compile time error here, ensure to have SDK 19+ used in your ADT/Eclipse. * You may even delete this block in case you don't need remote debugging or don't have an Android 4.4+ device in place. * Details: https://developers.google.com/chrome-developer-tools/docs/remote-debugging */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (0 != (getActivity().getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE)) { WebView.setWebContentsDebuggingEnabled(true); } } try { // load architectView's content this.architectView.load(this.getARchitectWorldPath()); if (this.getInitialCullingDistanceMeters() != ArchitectViewHolderInterface.CULLING_DISTANCE_DEFAULT_METERS) { // set the culling distance - meaning: the maximum distance to render geo-content this.architectView.setCullingDistance(this.getInitialCullingDistanceMeters()); } } catch (IOException e) { // unexpected, if error occurs here your path is invalid e.printStackTrace(); } // listener passed over to locationProvider, any location update is handled here this.locationListener = new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(final Location location) { if (location != null) { AbstractArchitectCamFragmentV4.this.lastKnownLocaton = location; if (AbstractArchitectCamFragmentV4.this.architectView != null) { // check if location has altitude at certain accuracy level & call right architect method (the one with altitude information) if (location.hasAltitude() && location.hasAccuracy() && location.getAccuracy() < 7) { AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getAccuracy()); } else { AbstractArchitectCamFragmentV4.this.architectView.setLocation(location.getLatitude(), location.getLongitude(), location.hasAccuracy() ? location.getAccuracy() : 1000); } } } } }; // set accuracy listener if implemented, you may e.g. show calibration prompt for compass using this listener this.sensorAccuracyListener = this.getSensorAccuracyListener(); // set urlListener, any calls made in JS like "document.location = 'architectsdk://foo?bar=123'" is forwarded to this listener, use this to interact between JS and native Android activity/fragment this.urlListener = this.getUrlListener(); // register valid urlListener in architectView, ensure this is set before content is loaded to not miss any event if (this.urlListener != null) { this.architectView.registerUrlListener(this.getUrlListener()); } // locationProvider used to fetch user position this.locationProvider = this.getLocationProvider(this.locationListener); }