create Mock Location Provider - Android Map

Android examples for Map:Location Provider

Description

create Mock Location Provider

Demo Code


//package com.java2s;

import android.location.LocationManager;
import android.location.LocationProvider;
import android.util.Log;

public class Main {
    public static final String TAG = "DSN Debug";

    public static void createMockLocationProvider(LocationManager manager,
            String provider) {//ww  w .  j ava  2 s  .  c  o  m
        Log.w(TAG, "Providers: " + manager.getAllProviders().toString());
        if (manager.getProvider(provider) != null) {
            Log.w(TAG, "Removing provider " + provider);
            manager.removeTestProvider(provider);
        }
        Log.w(TAG, "Providers: " + manager.getAllProviders().toString());

        if (manager.getProvider(provider) == null) {
            Log.w(TAG, "Adding provider " + provider + " again");
            manager.addTestProvider(provider, "requiresNetwork" == "",
                    "requiresSatellite" == "", "requiresCell" == "",
                    "hasMonetaryCost" == "", "supportsAltitude" == "",
                    "supportsSpeed" == "", "supportsBearing" == "",
                    android.location.Criteria.POWER_LOW,
                    android.location.Criteria.ACCURACY_FINE);
        }
        Log.w(TAG, "Providers: " + manager.getAllProviders().toString());

        manager.setTestProviderEnabled(provider, true);

        manager.setTestProviderStatus(provider, LocationProvider.AVAILABLE,
                null, System.currentTimeMillis());
    }
}

Related Tutorials