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.upmoon.alexanderbean.barcrawlr.fragments.PlanSelectorFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_plan_selector, container, false); /**/*from www . j a v a2 s . c o m*/ * Widgets here */ mLeftFAB = (FloatingActionButton) v.findViewById(R.id.connect_fab); mLeftFAB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder buildo = new AlertDialog.Builder(getActivity()); final EditText inp1 = new EditText(getActivity()); inp1.setInputType(InputType.TYPE_CLASS_TEXT); buildo.setTitle("Join Active Plan"); buildo.setView(inp1); buildo.setPositiveButton("Join", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface diag, int which) { AlertDialog.Builder buildo = new AlertDialog.Builder(getActivity()); final EditText inp2 = new EditText(getActivity()); inp2.setInputType(InputType.TYPE_CLASS_TEXT); buildo.setTitle("Choose a username"); buildo.setView(inp2); buildo.setPositiveButton("Join", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface diag, int which) { if (!inp2.getText().toString().equals("")) { GetPlan gp = new GetPlan(); gp.execute(inp1.getText().toString(), inp2.getText().toString()); } } }); buildo.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface diag, int which) { diag.cancel(); } }); buildo.show(); } }); buildo.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface diag, int which) { diag.cancel(); } }); buildo.show(); } }); mRightFAB = (FloatingActionButton) v.findViewById(R.id.new_plan_fab); mRightFAB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder buildo = new AlertDialog.Builder(getActivity()); final EditText inp = new EditText(getActivity()); inp.setInputType(InputType.TYPE_CLASS_TEXT); buildo.setTitle("Create New Plan"); buildo.setView(inp); buildo.setPositiveButton("Create", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface diag, int which) { PlanLoader pl = new PlanLoader(getActivity()); String planName = inp.getText().toString(); if (!planName.equals("") && pl.planNameExists(planName)) { Toast.makeText(getActivity(), "Invalid Name or name exists", Toast.LENGTH_SHORT).show(); } else { Plan plan = new Plan(); plan.setName(inp.getText().toString()); CurrentPlan.getInstance().setPlan(plan); Intent intent = new Intent(getActivity(), PlanCreator.class); startActivity(intent); } } }); buildo.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface diag, int which) { } }); buildo.show(); } }); //RecyclerView mAdapter = new PlanAdapter(); mRecyclerView = (RecyclerView) v.findViewById(R.id.gol_recycler_view); mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); mRecyclerView.setAdapter(mAdapter); /** * Load in plan data */ PlanListChanged(); /** * location */ locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. updateLocation(location.getLongitude(), location.getLatitude()); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; return v; }
From source file:com.android.gpstest.GpsTestActivity.java
/** Called when the activity is first created. */ @Override// ww w.j a va2 s. c o m public void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); sInstance = this; // Set the default values from the XML file if this is the first // execution of the app PreferenceManager.setDefaultValues(this, R.xml.preferences, false); mService = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Permission Denied Toast.makeText(this, getString(R.string.permission_denied), Toast.LENGTH_SHORT).show(); finish(); return; } else { mProvider = mService.getProvider(LocationManager.GPS_PROVIDER); if (mProvider == null) { Log.e(TAG, "Unable to get GPS_PROVIDER"); Toast.makeText(this, getString(R.string.gps_not_supported), Toast.LENGTH_SHORT).show(); finish(); return; } } mService.addGpsStatusListener(this); mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); // If we have a large screen, show all the fragments in one layout if (GpsTestUtil.isLargeScreen(this)) { setContentView(R.layout.activity_main_large_screen); mIsLargeScreen = true; } else { setContentView(R.layout.activity_main); } initActionBar(savedInstanceState); SharedPreferences settings = Application.getPrefs(); double tempMinTime = Double.valueOf(settings.getString(getString(R.string.pref_key_gps_min_time), getString(R.string.pref_gps_min_time_default_sec))); minTime = (long) (tempMinTime * SECONDS_TO_MILLISECONDS); minDistance = Float.valueOf(settings.getString(getString(R.string.pref_key_gps_min_distance), getString(R.string.pref_gps_min_distance_default_meters))); if (settings.getBoolean(getString(R.string.pref_key_auto_start_gps), true)) { gpsStart(); } }
From source file:io.kristal.locationplugin.LocationPlugin.java
/*********************************************************************************************** * * METHODS/*ww w . jav a 2s . c o m*/ * **********************************************************************************************/ private void getActiveProviders(Context context) { mProviders = new ArrayList<>(); mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (mLocationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)) { mProviders.add(LocationManager.PASSIVE_PROVIDER); } if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { mProviders.add(LocationManager.NETWORK_PROVIDER); } if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { mProviders.add(LocationManager.GPS_PROVIDER); } }
From source file:fr.louisbl.cordova.locationservices.CordovaLocationServices.java
private boolean isGPSdisabled() { LocationManager lm = null;/*ww w. j a v a2 s .c om*/ boolean gps_enabled; if (lm == null) lm = (LocationManager) this.cordova.getActivity().getSystemService(Context.LOCATION_SERVICE); try { gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); } catch (Exception ex) { ex.printStackTrace(); gps_enabled = false; } return !gps_enabled; }
From source file:com.microsoft.band.sdksample.SensorsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_sensors, container, false); senSensorManager1 = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); senSensorManager2 = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); senGyroscope = senSensorManager1.getDefaultSensor(Sensor.TYPE_GYROSCOPE); senSensorManager1.registerListener(this, senGyroscope, SensorManager.SENSOR_DELAY_NORMAL); senAccelerometer = senSensorManager2.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); senSensorManager2.registerListener(this, senAccelerometer, SensorManager.SENSOR_DELAY_NORMAL); mTableAcc = (TableLayout) rootView.findViewById(R.id.tableAcc); mTableAcc.setVisibility(View.GONE); mTextAccX = (TextView) rootView.findViewById(R.id.textAccX); mTextAccY = (TextView) rootView.findViewById(R.id.textAccY); mTextAccZ = (TextView) rootView.findViewById(R.id.textAccZ); mTextAngX = (TextView) rootView.findViewById(R.id.textPAngX); mTextAngY = (TextView) rootView.findViewById(R.id.textPAngY); mTextAngZ = (TextView) rootView.findViewById(R.id.textPAngZ); mTextLong = (TextView) rootView.findViewById(R.id.textLong); mTextLat = (TextView) rootView.findViewById(R.id.textLat); mTextTime = (TextView) rootView.findViewById(R.id.textTime); temp_list = new double[14]; c = 0;//from w w w. jav a 2 s.c om // Acquire a reference to the system Location Manager LocationManager locationManager = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); // Define a listener that responds to location updates LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. temp_list[12] = location.getLongitude(); temp_list[13] = location.getLatitude(); mTextLong.setText(Double.toString(temp_list[12])); mTextLat.setText(Double.toString(temp_list[13])); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(String provider) { } }; // Register the listener with the Location Manager to receive location updates locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); runnable.run(); // // Gyro setup // mTableGyro = (TableLayout) rootView.findViewById(R.id.tableGyro); mTableGyro.setVisibility(View.GONE); mTextGyroAccX = (TextView) rootView.findViewById(R.id.textGyroAccX); mTextGyroAccY = (TextView) rootView.findViewById(R.id.textGyroAccY); mTextGyroAccZ = (TextView) rootView.findViewById(R.id.textGyroAccZ); mTextGyroAngX = (TextView) rootView.findViewById(R.id.textAngX); mTextGyroAngY = (TextView) rootView.findViewById(R.id.textAngY); mTextGyroAngZ = (TextView) rootView.findViewById(R.id.textAngZ); // // Contact setup // mTableContact = (TableLayout) rootView.findViewById(R.id.tableContact); mTableContact.setVisibility(View.GONE); mTextContact = (TextView) rootView.findViewById(R.id.textContact); turnOnSensors(); return rootView; }
From source file:ca.ualberta.cs.cmput301w15t04team04project.FragmentEditClaim2.java
public void getClaimLocation(View view) { LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, listener); }
From source file:com.ibm.mf.geofence.demo.MapsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { log.debug("***************************************************************************************"); super.onCreate(savedInstanceState); setContentView(R.layout.maps_activity); mapCrossHair = (ImageView) findViewById(R.id.map_cross_hair); log.debug("in onCreate() tracking is " + (trackingEnabled ? "enabled" : "disabled")); addFenceButton = (Button) findViewById(R.id.addFenceButton); addFenceButton.setOnClickListener(new View.OnClickListener() { @Override//from w w w . ja v a 2s . c o m public void onClick(View v) { switchMode(); } }); if (savedInstanceState != null) { double[] loc = savedInstanceState.getDoubleArray("currentLocation"); if (loc != null) { currentLocation = new Location(LocationManager.NETWORK_PROVIDER); currentLocation.setLatitude(loc[0]); currentLocation.setLongitude(loc[1]); currentLocation.setTime(System.currentTimeMillis()); } currentZoom = savedInstanceState.getFloat("zoom", -1f); log.debug(String.format("restored currentLocation=%s; currentZoom=%f", currentLocation, currentZoom)); } if (currentLocation == null) { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); currentLocation = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } log.debug("onCreate() : init of geofencing service"); /* if (!dbDeleted) { dbDeleted = true; DemoUtils.deleteGeofenceDB(this); } */ initManager(); /* // testing the loading from a zip resource manager.loadGeofencesFromResource("com/ibm/pisdk/geofencing/geofence_2016-03-18_14_38_04.zip"); */ customHttpService = new CustomHttpService(manager, this, SERVER_URL, USER, PWD); try { startSimulation(geofenceHolder.getFences()); } catch (Exception e) { log.error("error in startSimulation()", e); } }
From source file:eu.geopaparazzi.library.gps.GpsService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { // GPLog.addLogEntry(this, "onStartCommand called with intent: " + intent); /*/*from w ww .j ava2 s . c o m*/ * If startService(intent) is called while the service is running, * its onStartCommand() is also called. Therefore your service needs * to be prepared that onStartCommand() can be called several times. */ if (preferences == null) { preferences = PreferenceManager.getDefaultSharedPreferences(this); useNetworkPositions = preferences.getBoolean(LibraryConstants.PREFS_KEY_GPS_USE_NETWORK_POSITION, false); isMockMode = preferences.getBoolean(LibraryConstants.PREFS_KEY_MOCKMODE, false); toastHandler = new Handler(); log("onStartCommand: Preferences created"); } if (locationManager == null) { locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return Service.START_FLAG_RETRY; } locationManager.addGpsStatusListener(this); isProviderEnabled = isGpsOn(); log("onStartCommand: LocationManager created + GpsService started"); } if (!isListeningForUpdates) { registerForLocationUpdates(); log("onStartCommand: Registered for location updates"); } if (intent != null) { /* * START GPS logging */ if (intent.hasExtra(START_GPS_LOGGING)) { boolean startGpsLogging = intent.getBooleanExtra(START_GPS_LOGGING, false); if (startGpsLogging) { log("onStartCommand: Start GPS logging called"); if (!isDatabaseLogging) { String gpsLogName = intent.getStringExtra(START_GPS_LOG_NAME); String gpsLogHelperClass = intent.getStringExtra(START_GPS_LOG_HELPER_CLASS); boolean continueLastGpsLog = intent.getBooleanExtra(START_GPS_CONTINUE_LOG, false); try { Class<?> logHelper = Class.forName(gpsLogHelperClass); IGpsLogDbHelper newInstance = (IGpsLogDbHelper) logHelper.newInstance(); startDatabaseLogging(gpsLogName, continueLastGpsLog, newInstance); } catch (Exception e) { GPLog.error(this, "Could not start logging", e); } } } } if (intent.hasExtra(STOP_GPS_LOGGING)) { boolean stopGpsLogging = intent.getBooleanExtra(STOP_GPS_LOGGING, false); if (stopGpsLogging) { log("onStartCommand: Stop GPS logging called"); if (isDatabaseLogging) { stopDatabaseLogging(); } } } if (intent.hasExtra(GPS_SERVICE_DO_BROADCAST)) { log("onStartCommand: broadcast trigger"); boolean doBroadcast = intent.getBooleanExtra(GPS_SERVICE_DO_BROADCAST, false); if (doBroadcast) { broadcast("triggered by onStartCommand Intent"); } } } return Service.START_REDELIVER_INTENT; }
From source file:com.appnexus.opensdk.AdRequest.java
private AdRequest(AdRequester adRequester, int httpRetriesLeft, int blankRetriesLeft) { owner = adRequester.getOwner();//from w w w . j av a 2s. c o m this.requester = adRequester; this.httpRetriesLeft = httpRetriesLeft; this.blankRetriesLeft = blankRetriesLeft; this.placementId = owner.getPlacementID(); context = owner.getContext(); String aid = android.provider.Settings.Secure.getString(context.getContentResolver(), Secure.ANDROID_ID); // Do we have access to location? if (context.checkCallingOrSelfPermission( "android.permission.ACCESS_FINE_LOCATION") == PackageManager.PERMISSION_GRANTED || context.checkCallingOrSelfPermission( "android.permission.ACCESS_COARSE_LOCATION") == PackageManager.PERMISSION_GRANTED) { // Get lat, long from any GPS information that might be currently // available LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); Location lastLocation = lm.getLastKnownLocation(lm.getBestProvider(new Criteria(), false)); if (lastLocation != null) { lat = "" + lastLocation.getLatitude(); lon = "" + lastLocation.getLongitude(); locDataAge = "" + (System.currentTimeMillis() - lastLocation.getTime()); locDataPrecision = "" + lastLocation.getAccuracy(); } } else { Clog.w(Clog.baseLogTag, Clog.getString(R.string.permissions_missing_location)); } // Do we have permission ACCESS_NETWORK_STATE? if (context.checkCallingOrSelfPermission( "android.permission.ACCESS_NETWORK_STATE") != PackageManager.PERMISSION_GRANTED) { Clog.e(Clog.baseLogTag, Clog.getString(R.string.permissions_missing_network_state)); fail(); this.cancel(true); return; } // Get orientation, the current rotation of the device orientation = context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? "h" : "v"; // Get hidmd5, hidsha1, the device ID hashed if (Settings.getSettings().hidmd5 == null) { Settings.getSettings().hidmd5 = HashingFunctions.md5(aid); } hidmd5 = Settings.getSettings().hidmd5; if (Settings.getSettings().hidsha1 == null) { Settings.getSettings().hidsha1 = HashingFunctions.sha1(aid); } hidsha1 = Settings.getSettings().hidsha1; // Get devMake, devModel, the Make and Model of the current device devMake = Settings.getSettings().deviceMake; devModel = Settings.getSettings().deviceModel; // Get carrier if (Settings.getSettings().carrierName == null) { Settings.getSettings().carrierName = ((TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE)).getNetworkOperatorName(); } carrier = Settings.getSettings().carrierName; // Get firstlaunch and convert it to a string firstlaunch = Settings.getSettings().first_launch; // Get ua, the user agent... ua = Settings.getSettings().ua; // Get wxh if (owner.isBanner()) { this.width = ((BannerAdView) owner).getAdWidth(); this.height = ((BannerAdView) owner).getAdHeight(); } maxHeight = owner.getContainerHeight(); maxWidth = owner.getContainerWidth(); if (Settings.getSettings().mcc == null || Settings.getSettings().mnc == null) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String networkOperator = tm.getNetworkOperator(); if (networkOperator != null && networkOperator.length() >= 6) { Settings.getSettings().mcc = networkOperator.substring(0, 3); Settings.getSettings().mnc = networkOperator.substring(3); } } mcc = Settings.getSettings().mcc; mnc = Settings.getSettings().mnc; ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); connection_type = wifi.isConnected() ? "wifi" : "wan"; dev_time = "" + System.currentTimeMillis(); if (owner instanceof InterstitialAdView) { // Make string for allowed_sizes allowedSizes = ""; ArrayList<Size> sizes = ((InterstitialAdView) owner).getAllowedSizes(); for (Size s : sizes) { allowedSizes += "" + s.width() + "x" + s.height(); // If not last size, add a comma if (sizes.indexOf(s) != sizes.size() - 1) allowedSizes += ","; } } nativeBrowser = owner.getOpensNativeBrowser() ? "1" : "0"; //Reserve price reserve = owner.getReserve(); if (reserve <= 0) { this.psa = owner.shouldServePSAs ? "1" : "0"; } else { this.psa = "0"; } age = owner.getAge(); if (owner.getGender() != null) { if (owner.getGender() == AdView.GENDER.MALE) { gender = "m"; } else if (owner.getGender() == AdView.GENDER.FEMALE) { gender = "f"; } else { gender = null; } } customKeywords = owner.getCustomKeywords(); mcc = Settings.getSettings().mcc; mnc = Settings.getSettings().mnc; language = Settings.getSettings().language; }
From source file:ca.rmen.android.networkmonitor.app.prefs.PreferenceFragmentActivity.java
/** * Checks if we have either the GPS or Network location provider enabled. If not, shows a popup dialog telling the user they should go to the system * settings to enable location tracking. *///from ww w.j ava 2 s. c om private void checkLocationSettings() { // If the user chose high accuracy, make sure we have at least one location provider. LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) || locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))) { DialogFragmentFactory.showConfirmDialog(this, getString(R.string.no_location_confirm_dialog_title), getString(R.string.no_location_confirm_dialog_message), ID_ACTION_LOCATION_SETTINGS, null); } else { finish(); } }