Search in sources :

Example 51 with Location

use of android.location.Location in project android_frameworks_base by ParanoidAndroid.

the class ExternalSharedPermsFLTest method testRunFineLocation.

/** The use of location manager below is simply to simulate an app that
     *  tries to use it, so we can verify whether permissions are granted and accessible.
     * */
public void testRunFineLocation() {
    LocationManager locationManager = (LocationManager) getInstrumentation().getContext().getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

        public void onLocationChanged(Location location) {
        }

        public void onProviderDisabled(String provider) {
        }

        public void onProviderEnabled(String provider) {
        }

        public void onStatusChanged(String provider, int status, Bundle extras) {
        }
    });
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Location(android.location.Location)

Example 52 with Location

use of android.location.Location in project android_frameworks_base by ParanoidAndroid.

the class FusionEngine method updateFusedLocation.

private void updateFusedLocation() {
    // may the best location win!
    if (isBetterThan(mGpsLocation, mNetworkLocation)) {
        mFusedLocation = new Location(mGpsLocation);
    } else {
        mFusedLocation = new Location(mNetworkLocation);
    }
    mFusedLocation.setProvider(FUSED);
    if (mNetworkLocation != null) {
        // copy NO_GPS_LOCATION extra from mNetworkLocation into mFusedLocation
        Bundle srcExtras = mNetworkLocation.getExtras();
        if (srcExtras != null) {
            Parcelable srcParcelable = srcExtras.getParcelable(LocationProviderBase.EXTRA_NO_GPS_LOCATION);
            if (srcParcelable instanceof Location) {
                Bundle dstExtras = mFusedLocation.getExtras();
                if (dstExtras == null) {
                    dstExtras = new Bundle();
                    mFusedLocation.setExtras(dstExtras);
                }
                dstExtras.putParcelable(LocationProviderBase.EXTRA_NO_GPS_LOCATION, (Location) srcParcelable);
            }
        }
    }
    if (mCallback != null) {
        mCallback.reportLocation(mFusedLocation);
    } else {
        Log.w(TAG, "Location updates received while fusion engine not started");
    }
}
Also used : Bundle(android.os.Bundle) Parcelable(android.os.Parcelable) Location(android.location.Location)

Example 53 with Location

use of android.location.Location in project ignition by mttkay.

the class AbstractIgnitedLocationManagerTest method ignitedLocationIsCurrentLocation.

@Test
public void ignitedLocationIsCurrentLocation() {
    resume();
    assertThat(lastKnownLocation, equalTo(activity.getCurrentLocation()));
    Location newLocation = sendMockLocationBroadcast(LocationManager.GPS_PROVIDER);
    assertThat(newLocation, equalTo(activity.getCurrentLocation()));
}
Also used : Location(android.location.Location) Test(org.junit.Test)

Example 54 with Location

use of android.location.Location in project ignition by mttkay.

the class AbstractIgnitedLocationManagerTest method sendMockLocationBroadcast.

protected Location sendMockLocationBroadcast(String provider, float accuracy, String action) {
    Intent intent = new Intent(action);
    Location location = getMockLocation(2.0, 2.0);
    intent.putExtra(LocationManager.KEY_LOCATION_CHANGED, location);
    shadowApp.sendBroadcast(intent);
    return location;
}
Also used : Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Location(android.location.Location)

Example 55 with Location

use of android.location.Location in project android-app-common-tasks by multidots.

the class GetCurrentLocationAct method init.

private void init() {
    tvLatitude = (TextView) findViewById(R.id.tvLatitude);
    tvLongitude = (TextView) findViewById(R.id.tvLongitude);
    Button btnLocation = (Button) findViewById(R.id.btnLocation);
    btnLocation.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //                if (Common.isNetworkAvailable(mContext)) {
            //                    if (Common.getGpsStatus(mContext)) {
            Location location = Common.getCurrentLocation(mContext);
            if (location != null) {
                tvLatitude.setText("" + location.getLatitude());
                tvLongitude.setText("" + location.getLongitude());
            } else {
                Common.showGPSDisabledAlert("Please enable your location or connect to cellular network.", GetCurrentLocationAct.this);
            }
        //                    } else {
        //                        Common.showGPSDisabledAlert("Please enable your location.", mContext);
        //                    }
        //                } else {
        //                    Toast.makeText(mContext, "Please Connect your device with internet.", Toast.LENGTH_LONG).show();
        //                    Common.showNETWORDDisabledAlert(mContext);
        //                }
        }
    });
}
Also used : Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) View(android.view.View) Location(android.location.Location)

Aggregations

Location (android.location.Location)290 Bundle (android.os.Bundle)50 LocationListener (android.location.LocationListener)38 LocationManager (android.location.LocationManager)33 ArrayList (java.util.ArrayList)29 Criteria (android.location.Criteria)20 LocationProviderInterface (com.android.server.location.LocationProviderInterface)18 GsmCellLocation (android.telephony.gsm.GsmCellLocation)17 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 BroadcastReceiver (android.content.BroadcastReceiver)12 Handler (android.os.Handler)10 MockProvider (com.android.server.location.MockProvider)9 Intent (android.content.Intent)8 Timer (java.util.Timer)8 Test (org.junit.Test)8 PendingIntent (android.app.PendingIntent)7 IOException (java.io.IOException)7 LocationProviderProxy (com.android.server.location.LocationProviderProxy)6 HashMap (java.util.HashMap)6 List (java.util.List)6