Example usage for android.content Context LOCATION_SERVICE

List of usage examples for android.content Context LOCATION_SERVICE

Introduction

In this page you can find the example usage for android.content Context LOCATION_SERVICE.

Prototype

String LOCATION_SERVICE

To view the source code for android.content Context LOCATION_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.location.LocationManager for controlling location updates.

Usage

From source file:com.nick.scalpel.core.AutoFoundWirer.java

private void wireFromContext(Context context, AutoFound.Type type, int idRes, Resources.Theme theme,
        Field field, Object forWho) {
    Resources resources = context.getResources();
    switch (type) {
    case STRING:/*from  w  ww.  j  av  a2 s.c o m*/
        setField(field, forWho, resources.getString(idRes));
        break;
    case COLOR:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, resources.getColor(idRes, theme));
        } else {
            //noinspection deprecation
            setField(field, forWho, resources.getColor(idRes));
        }
        break;
    case INTEGER:
        setField(field, forWho, resources.getInteger(idRes));
        break;
    case BOOL:
        setField(field, forWho, resources.getBoolean(idRes));
        break;
    case STRING_ARRAY:
        setField(field, forWho, resources.getStringArray(idRes));
        break;
    case INT_ARRAY:
        setField(field, forWho, resources.getIntArray(idRes));
        break;
    case PM:
        setField(field, forWho, context.getSystemService(Context.POWER_SERVICE));
        break;
    case ACCOUNT:
        setField(field, forWho, context.getSystemService(Context.ACCOUNT_SERVICE));
        break;
    case ALARM:
        setField(field, forWho, context.getSystemService(Context.ALARM_SERVICE));
        break;
    case AM:
        setField(field, forWho, context.getSystemService(Context.ACTIVITY_SERVICE));
        break;
    case WM:
        setField(field, forWho, context.getSystemService(Context.WINDOW_SERVICE));
        break;
    case NM:
        setField(field, forWho, context.getSystemService(Context.NOTIFICATION_SERVICE));
        break;
    case TM:
        setField(field, forWho, context.getSystemService(Context.TELEPHONY_SERVICE));
        break;
    case TCM:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.TELECOM_SERVICE));
        }
        break;
    case SP:
        setField(field, forWho, PreferenceManager.getDefaultSharedPreferences(context));
        break;
    case PKM:
        setField(field, forWho, context.getPackageManager());
        break;
    case HANDLE:
        setField(field, forWho, new Handler(Looper.getMainLooper()));
        break;
    case ASM:
        setField(field, forWho, context.getSystemService(Context.ACCESSIBILITY_SERVICE));
        break;
    case CAP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.CAPTIONING_SERVICE));
        }
        break;
    case KGD:
        setField(field, forWho, context.getSystemService(Context.KEYGUARD_SERVICE));
        break;
    case LOCATION:
        setField(field, forWho, context.getSystemService(Context.LOCATION_SERVICE));
        break;
    case SEARCH:
        setField(field, forWho, context.getSystemService(Context.SEARCH_SERVICE));
        break;
    case SENSOR:
        setField(field, forWho, context.getSystemService(Context.SENSOR_SERVICE));
        break;
    case STORAGE:
        setField(field, forWho, context.getSystemService(Context.STORAGE_SERVICE));
        break;
    case WALLPAPER:
        setField(field, forWho, context.getSystemService(Context.WALLPAPER_SERVICE));
        break;
    case VIBRATOR:
        setField(field, forWho, context.getSystemService(Context.VIBRATOR_SERVICE));
        break;
    case CONNECT:
        setField(field, forWho, context.getSystemService(Context.CONNECTIVITY_SERVICE));
        break;
    case NETWORK_STATUS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.NETWORK_STATS_SERVICE));
        }
        break;
    case WIFI:
        setField(field, forWho, context.getSystemService(Context.WIFI_SERVICE));
        break;
    case AUDIO:
        setField(field, forWho, context.getSystemService(Context.AUDIO_SERVICE));
        break;
    case FP:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            setField(field, forWho, context.getSystemService(Context.FINGERPRINT_SERVICE));
        }
        break;
    case MEDIA_ROUTER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setField(field, forWho, context.getSystemService(Context.MEDIA_ROUTER_SERVICE));
        }
        break;
    case SUB:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
            setField(field, forWho, context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE));
        }
        break;
    case IME:
        setField(field, forWho, context.getSystemService(Context.INPUT_METHOD_SERVICE));
        break;
    case CLIP_BOARD:
        setField(field, forWho, context.getSystemService(Context.CLIPBOARD_SERVICE));
        break;
    case APP_WIDGET:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.APPWIDGET_SERVICE));
        }
        break;
    case DEVICE_POLICY:
        setField(field, forWho, context.getSystemService(Context.DEVICE_POLICY_SERVICE));
        break;
    case DOWNLOAD:
        setField(field, forWho, context.getSystemService(Context.DOWNLOAD_SERVICE));
        break;
    case BATTERY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            setField(field, forWho, context.getSystemService(Context.BATTERY_SERVICE));
        }
        break;
    case NFC:
        setField(field, forWho, context.getSystemService(Context.NFC_SERVICE));
        break;
    case DISPLAY:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.DISPLAY_SERVICE));
        }
        break;
    case USER:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setField(field, forWho, context.getSystemService(Context.USER_SERVICE));
        }
        break;
    case APP_OPS:
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setField(field, forWho, context.getSystemService(Context.APP_OPS_SERVICE));
        }
        break;
    case BITMAP:
        setField(field, forWho, BitmapFactory.decodeResource(resources, idRes, null));
        break;
    }
}

From source file:com.nextgis.maplibui.service.TrackerService.java

@Override
public void onCreate() {
    super.onCreate();

    mHasGPSFix = false;// w w w. jav  a  2s .c o  m

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    mAlarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);

    IGISApplication application = (IGISApplication) getApplication();
    String authority = application.getAuthority();
    mContentUriTracks = Uri.parse("content://" + authority + "/" + TrackLayer.TABLE_TRACKS);
    mContentUriTrackPoints = Uri.parse("content://" + authority + "/" + TrackLayer.TABLE_TRACKPOINTS);

    mPoint = new GeoPoint();
    mValues = new ContentValues();

    SharedPreferences sharedPreferences = getSharedPreferences(getPackageName() + "_preferences",
            Constants.MODE_MULTI_PROCESS);
    mSharedPreferencesTemp = getSharedPreferences(TEMP_PREFERENCES, MODE_PRIVATE);

    String minTimeStr = sharedPreferences.getString(SettingsConstants.KEY_PREF_TRACKS_MIN_TIME, "2");
    String minDistanceStr = sharedPreferences.getString(SettingsConstants.KEY_PREF_TRACKS_MIN_DISTANCE, "10");
    long minTime = Long.parseLong(minTimeStr) * 1000;
    float minDistance = Float.parseFloat(minDistanceStr);

    mTicker = getString(R.string.tracks_running);
    mSmallIcon = R.drawable.ic_action_maps_directions_walk;

    Intent intentSplit = new Intent(this, TrackerService.class);
    intentSplit.setAction(ACTION_SPLIT);
    mSplitService = PendingIntent.getService(this, 0, intentSplit, PendingIntent.FLAG_UPDATE_CURRENT);

    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    if (!PermissionUtil.hasPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            || !PermissionUtil.hasPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION))
        return;

    mLocationManager.addGpsStatusListener(this);

    String provider = LocationManager.GPS_PROVIDER;
    if (mLocationManager.getAllProviders().contains(provider)) {
        mLocationManager.requestLocationUpdates(provider, minTime, minDistance, this);

        if (Constants.DEBUG_MODE)
            Log.d(Constants.TAG, "Tracker service request location updates for " + provider);
    }

    provider = LocationManager.NETWORK_PROVIDER;
    if (mLocationManager.getAllProviders().contains(provider)) {
        mLocationManager.requestLocationUpdates(provider, minTime, minDistance, this);

        if (Constants.DEBUG_MODE)
            Log.d(Constants.TAG, "Tracker service request location updates for " + provider);
    }

    NotificationHelper.showLocationInfo(this);
}

From source file:com.shadowmaps.example.GpsTestActivity.java

/** Called when the activity is first created. */
@Override// www.j  a  v a  2 s. c  o  m
public void onCreate(Bundle savedInstanceState) {
    setTheme(com.actionbarsherlock.R.style.Theme_Sherlock);
    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);
    recording = false;
    mService = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    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);

    // Request use of spinner for showing indeterminate progress, to show
    // the user something is going on during long-running operations
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    // 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();
    }
    if (!isShadowServiceRunning(ShadowMapsService.class)) {
        final String STARTUP_EXTRA = "com.shadowmaps.example.start";
        Intent i = new Intent(this, ShadowMapsService.class);
        i.putExtra(STARTUP_EXTRA, true);
        startService(i);
        Log.v("SERVICE", "Starting ShadowService in activity onCreate");
    }
}

From source file:ca.ualberta.cs.cmput301w15t04team04project.MainActivity.java

/**
 * Called to do initial creation of a fragment.<br>
 * This is called after onAttach(Activity) and before
 * onCreateView(LayoutInflater, ViewGroup, Bundle).<br>
 * Note that this can be called while the fragment's activity is still in
 * the process of being created.<br>
 * As such, you can not rely on things like the activity's content view
 * hierarchy being initialized at this point.<br>
 * If you want to do work once the activity itself is created, see
 * onActivityCreated(Bundle).<br>/*from w w  w.jav  a 2s . c  o m*/
 * 
 * @param savedInstanceState
 *            If the fragment is being re-created from a previous saved
 *            state, this is the state.
 */
/*
 * (non-Javadoc)
 * 
 * @see android.support.v4.app.FragmentActivity#onCreate(android.os.Bundle)
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // searchClaim.setVisible(true);
    setContentView(R.layout.activity_main);
    checker = new NetworkAvailabliltyCheck(getApplicationContext());
    user = SignInManager.loadFromFile(this);
    actionBar = getActionBar();
    actionBar.setTitle("My Local Claims");

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (checker.getNetworkAvailable()) {
        Toast.makeText(this, "net", Toast.LENGTH_SHORT).show();
        ClaimList claimList = MyLocalClaimListManager.loadClaimList(getApplicationContext(), user.getName());
        localController = new MyLocalClaimListController(claimList);
        localController.upload(getApplicationContext());
    }
    /*
     * if (location != null){ user.setHomelocation(location); TextView tv =
     * (TextView) findViewById(R.id.gpsHomeLocationTextView);
     * tv.setText("Lat: " + location.getLatitude() + "\nLong: " +
     * location.getLongitude()); }
     */
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 1, listener);

    initialisePaging();
}

From source file:br.liveo.ndrawer.ui.fragment.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO Auto-generated method stub      
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    mlblTime = (TextView) rootView.findViewById(R.id.lblTime);
    mTxtTime = (TextView) rootView.findViewById(R.id.txtTime);
    mlblSpeed = (TextView) rootView.findViewById(R.id.lblSpeed);
    mTxtSpeed = (TextView) rootView.findViewById(R.id.txtSpeed);
    mlblDistance = (TextView) rootView.findViewById(R.id.lblDistance);
    mTxtDistance = (TextView) rootView.findViewById(R.id.txtDistance);
    mlblTemp = (TextView) rootView.findViewById(R.id.lblTemp);
    mTxtTemp = (TextView) rootView.findViewById(R.id.txtTemp);
    mlblHum = (TextView) rootView.findViewById(R.id.lblHum);
    mTxtHum = (TextView) rootView.findViewById(R.id.txtHum);
    mBtnStart = (TextView) rootView.findViewById(R.id.btnStart);
    mlblMessage = (TextView) rootView.findViewById(R.id.lblMessage);

    mBtnStart.setOnClickListener(new View.OnClickListener() {
        @Override/*w  ww . j  ava 2  s.c o  m*/
        public void onClick(View view) {
            if (mBtnStart.getText().equals("    ")) {
                Toast.makeText(getActivity(), "??? !", Toast.LENGTH_SHORT).show();
                updateEvent("RIDING_START");
                insertTrack();
                mStartTime = System.currentTimeMillis();

                MovementProfile.status = 1;

                jsonArr = new ArrayList<JSONObject>();

                mTimer.schedule(timerTask, 1000, 1000);
                mBtnStart.setText("    ");
            } else {
                Toast.makeText(getActivity(), "??? .", Toast.LENGTH_SHORT).show();
                updateEvent("RIDING_STOP");
                updateTrack();
                MovementProfile.status = 0;

                clearUI();
                mTimer.cancel();
                mBtnStart.setText("    ");
            }
        }
    });

    mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    if (!mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
        enableGPS();

    rootView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    return rootView;
}

From source file:it.unipr.informatica.autobusparma.MappaFragment.java

public void initLoc(LocationManager locMan) {

    locMan = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    isGPSEnabled = locMan.isProviderEnabled(LocationManager.GPS_PROVIDER);

    if (!isGPSEnabled) {
        Toast.makeText(getActivity(), "GPS non attivo. \nVai nelle opzioni per attivarlo.", Toast.LENGTH_SHORT)
                .show();//w ww  .ja  v a  2  s. c  o  m
    }
    if (!isOnline()) {
        Toast.makeText(getActivity(), "Internet non attivo. \nVai nelle opzioni per attivarlo.",
                Toast.LENGTH_SHORT).show();
    }

}

From source file:com.metinkale.prayerapp.compass.Main.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mRefresh == item) {
        mOnlyNew = true;//from  ww w .ja  v a2  s.  co m
        if (PermissionUtils.get(this).pLocation) {
            LocationManager locMan = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

            locMan.removeUpdates(this);
            List<String> providers = locMan.getProviders(true);
            for (String provider : providers) {
                locMan.requestLocationUpdates(provider, 0, 0, this);
            }
        }
    } else if (mSwitch == item) {
        if (mMode == Mode.Map) {
            mSensorManager.registerListener(mMagAccel,
                    mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                    SensorManager.SENSOR_DELAY_GAME);
            mSensorManager.registerListener(mMagAccel,
                    mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD),
                    SensorManager.SENSOR_DELAY_GAME);

            updateFrag(Mode.TwoDim);

            mSwitch.setIcon(MaterialDrawableBuilder.with(this).setIcon(MaterialDrawableBuilder.IconValue.MAP)
                    .setColor(Color.WHITE).setToActionbarSize().build());
        } else if (PermissionUtils.get(this).pLocation) {
            mSensorManager.unregisterListener(mMagAccel);
            updateFrag(Mode.Map);
            mSwitch.setIcon(MaterialDrawableBuilder.with(this)
                    .setIcon(MaterialDrawableBuilder.IconValue.COMPASS_OUTLINE).setColor(Color.WHITE)
                    .setToActionbarSize().build());
        } else {
            Toast.makeText(this, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:au.id.tedp.mapdroid.Picker.java

public Location getLastLocation(Context ctx) {
    LocationManager locmgr = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
    Location l = locmgr.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    if (l != null)
        return l;
    return locmgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}

From source file:com.tdispatch.passenger.fragment.ControlCenterFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mLocationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
}

From source file:com.barak.pix.NewPostActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_new_post);

    // find the retained fragment on activity restarts
    FragmentManager fm = getSupportFragmentManager();
    mTaskFragment = (NewPostUploadTaskFragment) fm.findFragmentByTag(TAG_TASK_FRAGMENT);

    // create the fragment and data the first time
    if (mTaskFragment == null) {
        // add the fragment
        mTaskFragment = new NewPostUploadTaskFragment();
        fm.beginTransaction().add(mTaskFragment, TAG_TASK_FRAGMENT).commit();
    }//  w  ww  .ja v a2  s  .c  om

    mImageView = (ImageView) findViewById(R.id.new_post_picture);

    mImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showImagePicker();
        }
    });
    Bitmap selectedBitmap = mTaskFragment.getSelectedBitmap();
    Bitmap thumbnail = mTaskFragment.getThumbnail();
    if (selectedBitmap != null) {
        mImageView.setImageBitmap(selectedBitmap);
        mResizedBitmap = selectedBitmap;
    }
    if (thumbnail != null) {
        mThumbnail = thumbnail;
    }
    final EditText descriptionText = (EditText) findViewById(R.id.new_post_text);

    mSubmitButton = (Button) findViewById(R.id.new_post_submit);
    mSubmitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (mResizedBitmap == null) {
                Toast.makeText(NewPostActivity.this, "    !!!",
                        Toast.LENGTH_SHORT).show();
                return;
            }
            if (mLocation == null) {
                Toast.makeText(NewPostActivity.this, " ? ?", Toast.LENGTH_SHORT)
                        .show();
                return;
            }
            String postText = descriptionText.getText().toString();
            if (TextUtils.isEmpty(postText)) {
                descriptionText.setError(getString(R.string.error_required_field));
                return;
            }
            showProgressDialog(getString(R.string.post_upload_progress_message));
            mSubmitButton.setEnabled(false);

            Long timestamp = System.currentTimeMillis();

            String bitmapPath = "https://pictures-e88fc.firebaseio.com" + "/" + FirebaseUtil.getCurrentUserId()
                    + "/full/" + timestamp.toString() + "/";
            String thumbnailPath = "https://pictures-e88fc.firebaseio.com" + "/"
                    + FirebaseUtil.getCurrentUserId() + "/thumb/" + timestamp.toString() + "/";
            mTaskFragment.uploadPost(mResizedBitmap, bitmapPath, mThumbnail, thumbnailPath,
                    mFileUri.getLastPathSegment(), postText, mLocation.getLatitude(), mLocation.getLongitude());
        }
    });
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationListener = new MyLocationListener();
    if (checkPermission(Manifest.permission.ACCESS_COARSE_LOCATION, getApplicationContext(),
            NewPostActivity.this)) {
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, locationListener);
    } else {
        requestPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION, 11, getApplicationContext(),
                this);
    }
}