當前位置: 首頁>>代碼示例>>Java>>正文


Java Criteria.setPowerRequirement方法代碼示例

本文整理匯總了Java中android.location.Criteria.setPowerRequirement方法的典型用法代碼示例。如果您正苦於以下問題:Java Criteria.setPowerRequirement方法的具體用法?Java Criteria.setPowerRequirement怎麽用?Java Criteria.setPowerRequirement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.location.Criteria的用法示例。


在下文中一共展示了Criteria.setPowerRequirement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCriteria

import android.location.Criteria; //導入方法依賴的package包/類
/**
 * 設置定位參數
 *
 * @return {@link Criteria}
 */
private static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    // 設置定位精確度 Criteria.ACCURACY_COARSE比較粗略,Criteria.ACCURACY_FINE則比較精細
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    // 設置是否要求速度
    criteria.setSpeedRequired(false);
    // 設置是否允許運營商收費
    criteria.setCostAllowed(false);
    // 設置是否需要方位信息
    criteria.setBearingRequired(false);
    // 設置是否需要海拔信息
    criteria.setAltitudeRequired(false);
    // 設置對電源的需求
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    return criteria;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:LocationUtils.java

示例2: getCriteria

import android.location.Criteria; //導入方法依賴的package包/類
/**
 * 設置定位參數
 *
 * @return {@link Criteria}
 */
private static Criteria getCriteria() {
    Criteria criteria = new Criteria();
    //設置定位精確度 Criteria.ACCURACY_COARSE比較粗略,Criteria.ACCURACY_FINE則比較精細
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    //設置是否要求速度
    criteria.setSpeedRequired(false);
    // 設置是否允許運營商收費
    criteria.setCostAllowed(false);
    //設置是否需要方位信息
    criteria.setBearingRequired(false);
    //設置是否需要海拔信息
    criteria.setAltitudeRequired(false);
    // 設置對電源的需求
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    return criteria;
}
 
開發者ID:tututututututu,項目名稱:BaseCore,代碼行數:22,代碼來源:LocationUtils.java

示例3: setupLocationListener

import android.location.Criteria; //導入方法依賴的package包/類
@SuppressLint("MissingPermission")
private void setupLocationListener() {
    locationListener = new LocationListener();
    locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);

    TIME_TO_UPDATE = Integer.parseInt(sharedPreferences.getString("sync_frequency", "60")) * 1000;

    Criteria criteria = new Criteria();
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(true);
    criteria.setSpeedRequired(false);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setCostAllowed(true);

    bestProvider = locationManager.getBestProvider(criteria, false);

    locationManager.requestLocationUpdates(bestProvider, TIME_TO_UPDATE, DISTANCE_TO_CHANGE, locationListener);
}
 
開發者ID:STUDIO-apps,項目名稱:GeoShare_Android,代碼行數:20,代碼來源:TrackingService.java

示例4: setupLocationChangeListener

import android.location.Criteria; //導入方法依賴的package包/類
@SuppressLint("MissingPermission")
private void setupLocationChangeListener() {
/* SETTING UP LOCATION CHANGE LISTENER */
    locationListener = new LocationListener();
    locationManager = (LocationManager) Application.getContext().getSystemService(Context.LOCATION_SERVICE);
    locationServiceEnabled = locationManager != null && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

    Criteria criteria = new Criteria();
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(true);
    criteria.setSpeedRequired(false);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setCostAllowed(true);

    bestProvider = locationManager.getBestProvider(criteria, false);

    updateFrequency = Integer.parseInt(settingsSharedPreferences.getString("update_frequency", "5")) * 1000;

    locationManager.requestLocationUpdates(bestProvider, updateFrequency, 0, locationListener);
}
 
開發者ID:STUDIO-apps,項目名稱:GeoShare_Android,代碼行數:22,代碼來源:MapsFragment.java

示例5: getDistanceToUser

import android.location.Criteria; //導入方法依賴的package包/類
private Float getDistanceToUser(User u) {
    LocationManager locationManager = (LocationManager) getActivity().getSystemService(LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_MEDIUM);
    criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
    String locationProvider = locationManager.getBestProvider(criteria, false);
    Boolean hasLocationPermission = this.hasLocationPermission();
    if (hasLocationPermission && locationProvider != null) {
        Location myLocation = locationManager.getLastKnownLocation(locationProvider);
        Location userLocation = new Location("");
        if (u.location.getValid()) {
            userLocation.setLatitude(u.location.getLatitude());
            userLocation.setLongitude(u.location.getLongitude());
        } else {
            return null;
        }

        if (myLocation != null) {
            return myLocation.distanceTo(userLocation);
        } else {
            return null;
        }
    } else {
        return null;
    }
}
 
開發者ID:BandUp,項目名稱:band-up-android,代碼行數:27,代碼來源:UserItemFragment.java

示例6: OverlayView

import android.location.Criteria; //導入方法依賴的package包/類
public OverlayView(Context context)
{
    super(context);

    SensorManager sensors = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
    Sensor accelSensor = sensors.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    Sensor compassSensor = sensors.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
    Sensor gyroSensor = sensors.getDefaultSensor(Sensor.TYPE_GYROSCOPE);

    boolean isAccelAvailable = sensors.registerListener(this, accelSensor, SensorManager.SENSOR_DELAY_NORMAL);
    boolean isCompassAvailable = sensors.registerListener(this, compassSensor, SensorManager.SENSOR_DELAY_NORMAL);
    boolean isGyroAvailable = sensors.registerListener(this, gyroSensor, SensorManager.SENSOR_DELAY_NORMAL);

    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);

    String best = locationManager.getBestProvider(criteria, true);

    Log.v(DEBUG_TAG, "Best provider: " + best);

    locationManager.requestLocationUpdates(best, 50, 0, this);
}
 
開發者ID:prasang7,項目名稱:AugmentedReality-Android,代碼行數:25,代碼來源:OverlayView.java

示例7: getProvider

import android.location.Criteria; //導入方法依賴的package包/類
private String getProvider(LocationManager locationManager) {
    // 構建位置查詢條件
    Criteria criteria = new Criteria();
    // 查詢精度:高
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    // 速度
    criteria.setSpeedRequired(false);
    // 是否查詢海撥:否
    criteria.setAltitudeRequired(false);
    // 是否查詢方位角:否
    criteria.setBearingRequired(false);
    // 電量要求:低
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    // 返回最合適的符合條件的provider,第2個參數為true說明,如果隻有一個provider是有效的,則返回當前provider
    return locationManager.getBestProvider(criteria, true);
}
 
開發者ID:macouen,項目名稱:lunzi,代碼行數:17,代碼來源:MapLocationUtil.java

示例8: initServices

import android.location.Criteria; //導入方法依賴的package包/類
private void initServices() {
    // sensor manager
    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mOrientationSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION);

    // location manager
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    mLocationProvider = mLocationManager.getBestProvider(criteria, true);

}
 
開發者ID:li-yu,項目名稱:iTester,代碼行數:17,代碼來源:CompassActivity.java

示例9: GeoHelper

import android.location.Criteria; //導入方法依賴的package包/類
public GeoHelper(Context context) {
	//Constructor
	Log.i(TAG, "Initialize GeoHelper.");
	mContext = context;
	
	locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
	
	listAllProviders();
	criteria = new Criteria();
   	criteria.setAccuracy(Criteria.ACCURACY_COARSE);
   	criteria.setAltitudeRequired(false);
   	criteria.setCostAllowed(false);
   	criteria.setPowerRequirement(Criteria.POWER_LOW);
   	criteria.setSpeedRequired(false);
	
	chooseBestProvider();
   
}
 
開發者ID:sussman,項目名稱:androidomatic-keyer,代碼行數:19,代碼來源:GeoHelper.java

示例10: doServiceStart

import android.location.Criteria; //導入方法依賴的package包/類
private void doServiceStart(Intent intent) {
  int updateRate = intent.getIntExtra(EXTRA_UPDATE_RATE, -1);
  if (updateRate == -1) {
    updateRate = 60000;
  }
  Criteria criteria = new Criteria();
  criteria.setAccuracy(Criteria.NO_REQUIREMENT);
  criteria.setPowerRequirement(Criteria.POWER_LOW);
  String bestProvider = locationManager.getBestProvider(criteria, true);
  locationManager.requestLocationUpdates(bestProvider, updateRate, 0, this);
  Intent toLaunch = new Intent(getApplicationContext(), SimpleServiceActivity.class);
  PendingIntent intentBack = PendingIntent.getActivity(getApplicationContext(), 0, toLaunch, 0);
  NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());
  builder.setTicker("Builder GPS Tracking");
  builder.setSmallIcon(android.R.drawable.stat_notify_more);
  builder.setWhen(System.currentTimeMillis());
  builder.setContentTitle("Builder GPS Tracking");
  builder.setContentText("Tracking start at " + updateRate + "ms intervals with [" + bestProvider + "] as the provider.");
  builder.setContentIntent(intentBack);
  builder.setAutoCancel(true);
  Notification notify = builder.build();
  notificationManager.notify(GPS_NOTIFY, notify);
}
 
開發者ID:rylexr,項目名稱:android-simple-service-app,代碼行數:24,代碼來源:GPXService.java

示例11: getProviderName

import android.location.Criteria; //導入方法依賴的package包/類
/**
 * Get the best provider name.
 * @return Name of best suiting provider.
 * */
String getProviderName() {
    LocationManager locationManager = (LocationManager) this
            .getSystemService(Context.LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    criteria.setPowerRequirement(Criteria.POWER_HIGH); // Chose your desired power consumption level.
    criteria.setAccuracy(Criteria.ACCURACY_MEDIUM); // Choose your accuracy requirement.
    criteria.setSpeedRequired(true); // Chose if speed for first location fix is required.
    criteria.setAltitudeRequired(false); // Choose if you use altitude.
    criteria.setBearingRequired(false); // Choose if you use bearing.
    criteria.setCostAllowed(true); // Choose if this provider can waste money :-)

    // Provide your criteria and flag enabledOnly that tells
    // LocationManager only to return active providers.
    return locationManager.getBestProvider(criteria, true);
}
 
開發者ID:hyalis,項目名稱:Bouako,代碼行數:21,代碼來源:FormActivity.java

示例12: shouldReturnBestCustomProviderUsingCriteria

import android.location.Criteria; //導入方法依賴的package包/類
@Test
public void shouldReturnBestCustomProviderUsingCriteria() throws Exception {
  Criteria criteria = new Criteria();
  Criteria customProviderCriteria = new Criteria();

  // Manually set best provider should be returned
  ArrayList<Criteria> criteriaList = new ArrayList<Criteria>();
  customProviderCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
  criteriaList.add(customProviderCriteria);
  shadowLocationManager.setProviderEnabled("BEST_ENABLED_PROVIDER_WITH_CRITERIA", true, criteriaList);
  assertTrue(shadowLocationManager.setBestProvider("BEST_ENABLED_PROVIDER_WITH_CRITERIA", true));
  criteria.setAccuracy(Criteria.ACCURACY_COARSE);
  criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
  assertThat("BEST_ENABLED_PROVIDER_WITH_CRITERIA").isEqualTo(locationManager.getBestProvider(criteria, true));
  assertTrue(shadowLocationManager.setBestProvider("BEST_ENABLED_PROVIDER_WITH_CRITERIA", true));
  assertThat("BEST_ENABLED_PROVIDER_WITH_CRITERIA").isEqualTo(locationManager.getBestProvider(criteria, false));
  assertThat("BEST_ENABLED_PROVIDER_WITH_CRITERIA").isEqualTo(locationManager.getBestProvider(criteria, true));
}
 
開發者ID:qx,項目名稱:FullRobolectricTestSample,代碼行數:19,代碼來源:LocationManagerTest.java

示例13: shouldReturnBestProviderUsingCriteria

import android.location.Criteria; //導入方法依賴的package包/類
@Test
public void shouldReturnBestProviderUsingCriteria() {
  Criteria criteria = new Criteria();

  shadowLocationManager.setProviderEnabled(LocationManager.GPS_PROVIDER, false);
  criteria.setAccuracy(Criteria.ACCURACY_FINE);
  assertThat(LocationManager.GPS_PROVIDER).isEqualTo(locationManager.getBestProvider(criteria, false));

  shadowLocationManager.setProviderEnabled(LocationManager.NETWORK_PROVIDER, false);
  criteria.setAccuracy(Criteria.ACCURACY_COARSE);
  assertThat(LocationManager.NETWORK_PROVIDER).isEqualTo(locationManager.getBestProvider(criteria, false));

  criteria.setPowerRequirement(Criteria.POWER_LOW);
  criteria.setAccuracy(Criteria.ACCURACY_FINE);
  assertThat(LocationManager.NETWORK_PROVIDER).isEqualTo(locationManager.getBestProvider(criteria, false));
}
 
開發者ID:qx,項目名稱:FullRobolectricTestSample,代碼行數:17,代碼來源:LocationManagerTest.java

示例14: onCreate

import android.location.Criteria; //導入方法依賴的package包/類
@Override
public void onCreate() {
	super.onCreate();
	mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
	// 查詢條件
	Criteria criteria = new Criteria();
	// 精確度
	criteria.setAccuracy(Criteria.ACCURACY_FINE);
	// 關心海拔
	criteria.setAltitudeRequired(true);
	// 運行產生開銷
	criteria.setCostAllowed(true);
	// 允許最大電量請求
	criteria.setPowerRequirement(Criteria.POWER_HIGH);
	String provider = mLocationManager.getBestProvider(criteria, true);
	Logger.i(TAG, "最好的提供者:" + provider);
	mPhoneLocationListener = new PhoneLocationListener();
	mLocationManager.requestLocationUpdates(provider, 0, 0, mPhoneLocationListener);
}
 
開發者ID:bingoogolapple,項目名稱:Graduation-Design,代碼行數:20,代碼來源:PhoneLocationService.java

示例15: criteriaFromRequest

import android.location.Criteria; //導入方法依賴的package包/類
/**
 * Builds a {@link android.location.Criteria} object from a {@link net.frakbot.android.location.common.LocationHubRequest}
 * that holds the requirements for the {@link android.location.Location} the caller wants.
 * <p/>
 * You can override this method and implement your own {@link net.frakbot.android.location.common.LocationHubRequest}
 * to {@link android.location.Criteria} transformation.
 *
 * @param request The original {@link net.frakbot.android.location.common.LocationHubRequest}
 *                with all of the desired requirements of {@link android.location.Location}.
 * @return A {@link android.location.Criteria} with a good approximation of location requirements.
 */
protected Criteria criteriaFromRequest(LocationHubRequest request) {
    Criteria criteria = new Criteria();
    if (request.getPriority() == LocationHubRequest.PRIORITY_NO_POWER) {
        // w/ PRIORITY_NO_POWER, also require ACCURACY_COARSE
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
    } else if (request.getPriority() == LocationHubRequest.PRIORITY_LOW_POWER) {
        // on PRIORITY_LOW_POWER, don't care about accuracy
        criteria.setPowerRequirement(Criteria.POWER_LOW);
    } else if (request.getPriority() == LocationHubRequest.PRIORITY_BALANCED_POWER_ACCURACY) {
        // on PRIORITY_BALANCED_POWER_ACCURACY, don't care about accuracy
        criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
    } else if (request.getPriority() == LocationHubRequest.PRIORITY_HIGH_ACCURACY) {
        // w/ PRIORITY_HIGH_ACCURACY, also require ACCURACY_FINE
        criteria.setPowerRequirement(Criteria.POWER_HIGH);
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
    }
    return criteria;
}
 
開發者ID:frakbot,項目名稱:AndroidLocationHub,代碼行數:31,代碼來源:AndroidLocationHubAdapter.java


注:本文中的android.location.Criteria.setPowerRequirement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。