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.vonglasow.michael.satstat.ui.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); DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss", Locale.ROOT); fmt.setTimeZone(TimeZone.getTimeZone("UTC")); String fileName = String.format("satstat-%s.log", fmt.format(new Date(System.currentTimeMillis()))); File dumpFile = new File(dumpDir, fileName); PrintStream s;//from w ww . j ava 2 s . c om 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(); Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri contentUri = Uri.fromFile(dumpFile); mediaScanIntent.setData(contentUri); c.sendBroadcast(mediaScanIntent); } catch (FileNotFoundException e2) { e2.printStackTrace(); } defaultUEH.uncaughtException(t, e); } }); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mSharedPreferences.registerOnSharedPreferenceChangeListener(this); prefUnitType = mSharedPreferences.getBoolean(Const.KEY_PREF_UNIT_TYPE, prefUnitType); prefKnots = mSharedPreferences.getBoolean(Const.KEY_PREF_KNOTS, prefKnots); prefCoord = Integer .valueOf(mSharedPreferences.getString(Const.KEY_PREF_COORD, Integer.toString(prefCoord))); prefUtc = mSharedPreferences.getBoolean(Const.KEY_PREF_UTC, prefUtc); prefCid = mSharedPreferences.getBoolean(Const.KEY_PREF_CID, prefCid); prefCid2 = mSharedPreferences.getBoolean(Const.KEY_PREF_CID2, prefCid2); prefWifiSort = Integer .valueOf(mSharedPreferences.getString(Const.KEY_PREF_WIFI_SORT, Integer.toString(prefWifiSort))); prefMapOffline = mSharedPreferences.getBoolean(Const.KEY_PREF_MAP_OFFLINE, prefMapOffline); prefMapPath = mSharedPreferences.getString(Const.KEY_PREF_MAP_PATH, prefMapPath); ActionBar actionBar = getSupportActionBar(); setContentView(R.layout.activity_main); // 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(TAG, "isWideScreen=" + Boolean.toString(isWideScreen)); // Create the adapter that will return a fragment for each of the // 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); Context ctx = new ContextThemeWrapper(getApplication(), R.style.AppTheme); mTabLayout = new TabLayout(ctx); LinearLayout.LayoutParams mTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); mTabLayout.setLayoutParams(mTabLayoutParams); for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { TabLayout.Tab newTab = mTabLayout.newTab(); newTab.setIcon(mSectionsPagerAdapter.getPageIcon(i)); mTabLayout.addTab(newTab); } actionBar.setDisplayShowCustomEnabled(true); actionBar.setCustomView(mTabLayout); mTabLayout.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager)); mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mTabLayout)); // This is needed by the mapsforge library. AndroidGraphicFactory.createInstance(this.getApplication()); // Get system services for event delivery locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mOrSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION); mAccSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mGyroSensor = sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE); mMagSensor = sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); mLightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT); mProximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); mPressureSensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE); mHumiditySensor = sensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY); mTempSensor = sensorManager.getDefaultSensor(Sensor.TYPE_AMBIENT_TEMPERATURE); telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); }
From source file:edu.pdx.cecs.orcycle.MyApplication.java
public Location getLastKnownLocation() { LocationManager lm = null;/* w ww . j a va 2 s .co m*/ List<String> providers = null; Location location = null; if (null != (lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE))) { if (null != (providers = lm.getProviders(true))) { /* Loop over the array backwards, and if you get a location, then break out the loop*/ for (int i = providers.size() - 1; i >= 0; --i) { if (null != (location = lm.getLastKnownLocation(providers.get(i)))) { break; } } } } return location; }
From source file:com.anton.gavel.GavelMain.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @Override//from w ww . java2s. c om public void onClick(View arg0) { //click listener for location button LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_HIGH); //String provider = locationManager.getBestProvider(criteria, true); locationManager.requestSingleUpdate(criteria, new LocationListener() { @Override public void onLocationChanged(Location location) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) createDialog(DIALOG_NO_GEOCODING); else if (Geocoder.isPresent()) (new ReverseGeocodingTask(getBaseContext())).execute(new Location[] { location }); // Invoking reverse geocoding in an AsyncTask. } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }, null); }
From source file:com.trigger_context.Main_Service.java
private boolean testConditions(String mac) { SharedPreferences conditions = getSharedPreferences(mac, MODE_PRIVATE); Map<String, ?> cond_map = conditions.getAll(); Set<String> key_set = cond_map.keySet(); boolean takeAction = true; if (key_set.contains("bluetooth")) { // checking the current state against the state set by the user final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); takeAction = new Boolean(bluetoothAdapter.isEnabled()) .equals(conditions.getString("bluetooth", "false")); }/*w w w. j a va 2 s. c o m*/ if (takeAction && key_set.contains("wifi")) { final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); takeAction = new Boolean(wm.isWifiEnabled()) == conditions.getBoolean("wifi", false); } if (takeAction && key_set.contains("gps")) { final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); takeAction = new Boolean(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) .equals(conditions.getString("gps", "false")); } if (takeAction && key_set.contains("sms")) { final Uri SMS_INBOX = Uri.parse("content://sms/inbox"); Cursor c = getContentResolver().query(SMS_INBOX, null, "read = 0", null, null); if (c != null) { int unreadMessagesCount = c.getCount(); c.close(); takeAction = new Boolean(unreadMessagesCount > 0).equals(conditions.getString("sms", "false")); } else { takeAction = false; } } // "NOT TESTED" head set, missed call, accelerometer, proximity, gyro, // orientation if (takeAction && key_set.contains("headset")) { AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); takeAction = am.isMusicActive() == conditions.getBoolean("headset", false); // am.isWiredHeadsetOn() is deprecated } /* * if(takeAction && key_set.contains("missedCall")) { final String[] * projection = null; final String selection = null; final String[] * selectionArgs = null; final String sortOrder = * android.provider.CallLog.Calls.DATE + " DESC"; Cursor cursor = null; * try{ cursor = getApplicationContext().getContentResolver().query( * Uri.parse("content://call_log/calls"), projection, selection, * selectionArgs, sortOrder); while (cursor.moveToNext()) { String * callLogID = * cursor.getString(cursor.getColumnIndex(android.provider.CallLog * .Calls._ID)); String callNumber = * cursor.getString(cursor.getColumnIndex * (android.provider.CallLog.Calls.NUMBER)); String callDate = * cursor.getString * (cursor.getColumnIndex(android.provider.CallLog.Calls.DATE)); String * callType = * cursor.getString(cursor.getColumnIndex(android.provider.CallLog * .Calls.TYPE)); String isCallNew = * cursor.getString(cursor.getColumnIndex * (android.provider.CallLog.Calls.NEW)); if(Integer.parseInt(callType) * == android.provider.CallLog.Calls.MISSED_CALL_TYPE && * Integer.parseInt(isCallNew) > 0){ * * } } }catch(Exception ex){ }finally{ cursor.close(); } * * } */ return takeAction; }
From source file:com.mendhak.gpslogger.GpsLoggingService.java
@SuppressWarnings("ResourceType") private void startPassiveManager() { if (preferenceHelper.getChosenListeners().contains(LocationManager.PASSIVE_PROVIDER)) { LOG.debug("Starting passive location listener"); if (passiveLocationListener == null) { passiveLocationListener = new GeneralLocationListener(this, "PASSIVE"); }/*w ww .ja v a2 s . co m*/ passiveLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); passiveLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 1000, 0, passiveLocationListener); } }
From source file:de.vanita5.twittnuker.activity.support.ComposeActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { // requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mPreferences = SharedPreferencesWrapper.getInstance(this, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); mBottomSendButton = mPreferences.getBoolean(KEY_BOTTOM_SEND_BUTTON, false); mTwitterWrapper = getTwittnukerApplication().getTwitterWrapper(); mResolver = getContentResolver();/* w w w . ja v a2s . c o m*/ mValidator = new TwidereValidator(this); setContentView(getLayoutInflater().inflate(R.layout.activity_compose, null)); setProgressBarIndeterminateVisibility(false); setFinishOnTouchOutside(false); mAccountIds = getAccountIds(this); if (mAccountIds.length <= 0) { final Intent intent = new Intent(INTENT_ACTION_TWITTER_LOGIN); intent.setClass(this, SignInActivity.class); startActivity(intent); finish(); return; } mBottomMenuBar.setIsBottomBar(true); mBottomMenuBar.setOnMenuItemClickListener(this); mActionMenuBar.setOnMenuItemClickListener(this); mEditText.setOnEditorActionListener(mPreferences.getBoolean(KEY_QUICK_SEND, false) ? this : null); mEditText.addTextChangedListener(this); mAccountSelectorAdapter = new AccountSelectorAdapter(this); mAccountSelector.setAdapter(mAccountSelectorAdapter); mAccountSelector.setOnItemClickListener(this); mAccountSelector.setOnItemLongClickListener(this); mAccountSelector.setScrollAfterItemClickEnabled(false); mAccountSelector.setScrollRightSpacingEnabled(false); mMediaPreviewAdapter = new MediaPreviewAdapter(this); mMediasPreviewGrid.setAdapter(mMediaPreviewAdapter); final Intent intent = getIntent(); if (savedInstanceState != null) { // Restore from previous saved state mSendAccountIds = savedInstanceState.getLongArray(EXTRA_ACCOUNT_IDS); mIsPossiblySensitive = savedInstanceState.getBoolean(EXTRA_IS_POSSIBLY_SENSITIVE); final ArrayList<ParcelableMediaUpdate> mediasList = savedInstanceState .getParcelableArrayList(EXTRA_MEDIAS); if (mediasList != null) { addMedias(mediasList); } mInReplyToStatus = savedInstanceState.getParcelable(EXTRA_STATUS); mInReplyToStatusId = savedInstanceState.getLong(EXTRA_STATUS_ID); mMentionUser = savedInstanceState.getParcelable(EXTRA_USER); mDraftItem = savedInstanceState.getParcelable(EXTRA_DRAFT); mShouldSaveAccounts = savedInstanceState.getBoolean(EXTRA_SHOULD_SAVE_ACCOUNTS); mOriginalText = savedInstanceState.getString(EXTRA_ORIGINAL_TEXT); mTempPhotoUri = savedInstanceState.getParcelable(EXTRA_TEMP_URI); } else { // The activity was first created final int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); final long notificationAccount = intent.getLongExtra(EXTRA_NOTIFICATION_ACCOUNT, -1); if (notificationId != -1) { mTwitterWrapper.clearNotificationAsync(notificationId, notificationAccount); } if (!handleIntent(intent)) { handleDefaultIntent(intent); } if (mSendAccountIds == null || mSendAccountIds.length == 0) { final long[] ids_in_prefs = ArrayUtils .parseLongArray(mPreferences.getString(KEY_COMPOSE_ACCOUNTS, null), ','); final long[] intersection = ArrayUtils.intersection(ids_in_prefs, mAccountIds); mSendAccountIds = intersection.length > 0 ? intersection : mAccountIds; } mOriginalText = ParseUtils.parseString(mEditText.getText()); } if (!setComposeTitle(intent)) { setTitle(R.string.compose); } final boolean useBottomMenu = isSingleAccount() || !mBottomSendButton; if (useBottomMenu) { mBottomMenuBar.inflate(R.menu.menu_compose); } else { mActionMenuBar.inflate(R.menu.menu_compose); } mBottomMenuBar.setVisibility(useBottomMenu ? View.VISIBLE : View.GONE); mActionMenuBar.setVisibility(useBottomMenu ? View.GONE : View.VISIBLE); mSendView.setVisibility(mBottomSendButton ? View.GONE : View.VISIBLE); mBottomSendDivider.setVisibility(mBottomSendButton ? View.VISIBLE : View.GONE); mBottomSendView.setVisibility(mBottomSendButton ? View.VISIBLE : View.GONE); mSendView.setOnClickListener(this); mBottomSendView.setOnClickListener(this); mSendView.setOnLongClickListener(this); mBottomSendView.setOnLongClickListener(this); final LinearLayout.LayoutParams bottomMenuContainerParams = (LinearLayout.LayoutParams) mBottomMenuContainer .getLayoutParams(); final LinearLayout.LayoutParams accountSelectorParams = (LinearLayout.LayoutParams) mAccountSelector .getLayoutParams(); final int maxItemsShown; final Resources res = getResources(); if (isSingleAccount()) { accountSelectorParams.weight = 0; accountSelectorParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; bottomMenuContainerParams.weight = 1; bottomMenuContainerParams.width = ViewGroup.LayoutParams.MATCH_PARENT; maxItemsShown = res.getInteger(R.integer.max_compose_menu_buttons_bottom_singleaccount); mAccountSelectorDivider.setVisibility(View.VISIBLE); } else { accountSelectorParams.weight = 1; accountSelectorParams.width = ViewGroup.LayoutParams.MATCH_PARENT; bottomMenuContainerParams.weight = 0; bottomMenuContainerParams.width = ViewGroup.LayoutParams.WRAP_CONTENT; maxItemsShown = res.getInteger(R.integer.max_compose_menu_buttons_bottom); mAccountSelectorDivider.setVisibility(mBottomSendButton ? View.GONE : View.VISIBLE); } mBottomMenuContainer.setLayoutParams(bottomMenuContainerParams); mBottomMenuBar.setMaxItemsShown(maxItemsShown); setMenu(); updateAccountSelection(); updateMediasPreview(); }
From source file:com.crearo.gpslogger.GpsLoggingService.java
private void startPassiveManager() { if (preferenceHelper.getChosenListeners().contains(LocationManager.PASSIVE_PROVIDER)) { LOG.debug("Starting passive location listener"); if (passiveLocationListener == null) { passiveLocationListener = new GeneralLocationListener(this, "PASSIVE"); }//from w ww .j a va2s .c o m passiveLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); passiveLocationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, 1000, 0, passiveLocationListener); } }
From source file:com.TakeTaxi.jy.MainMapScreen.java
public void getLocalPosition() { lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria crit = new Criteria(); towers = lm.getBestProvider(crit, false); Location location = lm.getLastKnownLocation(towers); if (location != null) { // changed lat/longi to temp for device testing tempLat = (int) (location.getLatitude() * 1E6); tempLongi = (int) (location.getLongitude() * 1E6); } else {/*w w w . java2s.co m*/ // /////////////////////////////////////////////////////////////////////////////////// // SHOULD PUT A NO NETWORK/GPS LOC ALERT // ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////////// } }
From source file:com.mendhak.gpslogger.GpsLoggingService.java
/** * Starts the location manager. There are two location managers - GPS and * Cell Tower. This code determines which manager to request updates from * based on user preference and whichever is enabled. If GPS is enabled on * the phone, that is used. But if the user has also specified that they * prefer cell towers, then cell towers are used. If neither is enabled, * then nothing is requested./*from ww w . j a va2 s.c om*/ */ @SuppressWarnings("ResourceType") private void startGpsManager() { //If the user has been still for more than the minimum seconds if (userHasBeenStillForTooLong()) { LOG.info("No movement detected in the past interval, will not log"); setAlarmForNextPoint(); return; } if (gpsLocationListener == null) { gpsLocationListener = new GeneralLocationListener(this, "GPS"); } if (towerLocationListener == null) { towerLocationListener = new GeneralLocationListener(this, "CELL"); } gpsLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); towerLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); checkTowerAndGpsStatus(); if (Session.isGpsEnabled() && preferenceHelper.getChosenListeners().contains(LocationManager.GPS_PROVIDER)) { LOG.info("Requesting GPS location updates"); // gps satellite based gpsLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, gpsLocationListener); gpsLocationManager.addGpsStatusListener(gpsLocationListener); gpsLocationManager.addNmeaListener(gpsLocationListener); Session.setUsingGps(true); startAbsoluteTimer(); } if (Session.isTowerEnabled() && (preferenceHelper.getChosenListeners().contains(LocationManager.NETWORK_PROVIDER) || !Session.isGpsEnabled())) { LOG.info("Requesting cell and wifi location updates"); Session.setUsingGps(false); // Cell tower and wifi based towerLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, towerLocationListener); startAbsoluteTimer(); } if (!Session.isTowerEnabled() && !Session.isGpsEnabled()) { LOG.error("No provider available!"); Session.setUsingGps(false); LOG.error(getString(R.string.gpsprovider_unavailable)); stopLogging(); setLocationServiceUnavailable(); return; } EventBus.getDefault().post(new ServiceEvents.WaitingForLocation(true)); Session.setWaitingForLocation(true); }
From source file:com.davidmascharka.lips.TrackerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //allow users to go back to Main Activity //TODO: test if this works on Marshmallow if (Build.VERSION.SDK_INT >= 23) { getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setDisplayShowHomeEnabled(true); } else {/*from w ww. j a v a 2 s . c o m*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { requestMyPermissions(); } setContentView(R.layout.activity_tracker); if (savedInstanceState == null) { getSupportFragmentManager().beginTransaction().add(R.id.container, new TrackerFragment()).commit(); } rotation = new float[9]; inclination = new float[9]; orientation = new float[3]; sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { updateLocation(location); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }; loadXClassifierModels(); loadYClassifierModels(); loadPartitionClassifierModels(); setUpXInstances(); setUpYInstances(); setUpPartitionInstances(); wifiReadings = new LinkedHashMap<String, Integer>(); t = new Thread(); t.start(); //load5PartitionClassifiers = new Thread(); //load5PartitionClassifiers.start(); }