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


Java Criteria.setCostAllowed方法代碼示例

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


在下文中一共展示了Criteria.setCostAllowed方法的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: getLocation

import android.location.Criteria; //導入方法依賴的package包/類
public static String getLocation(Context context) {
    if (context == null) {
        return "";
    }
    try {
        LocationManager locationManager = (LocationManager) context.getSystemService(HOME_RECOMMEND_PARAMETERS.LOCATION);
        Criteria criteria = new Criteria();
        criteria.setCostAllowed(false);
        criteria.setAccuracy(2);
        String bestProvider = locationManager.getBestProvider(criteria, true);
        if (bestProvider != null) {
            Location lastKnownLocation = locationManager.getLastKnownLocation(bestProvider);
            if (lastKnownLocation == null) {
                return "";
            }
            double latitude = lastKnownLocation.getLatitude();
            g = latitude + "*" + lastKnownLocation.getLongitude();
            return g;
        }
    } catch (Throwable e) {
        f.b("getLocation", "getLocation>>>", e);
    }
    return "";
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:25,代碼來源:Util.java

示例3: getLocation

import android.location.Criteria; //導入方法依賴的package包/類
public static String getLocation(Context context) {
    if (context == null) {
        return "";
    }
    try {
        LocationManager locationManager = (LocationManager) context.getSystemService
                ("location");
        Criteria criteria = new Criteria();
        criteria.setCostAllowed(false);
        criteria.setAccuracy(2);
        String bestProvider = locationManager.getBestProvider(criteria, true);
        if (bestProvider != null) {
            Location lastKnownLocation = locationManager.getLastKnownLocation(bestProvider);
            if (lastKnownLocation == null) {
                return "";
            }
            double latitude = lastKnownLocation.getLatitude();
            g = latitude + "*" + lastKnownLocation.getLongitude();
            return g;
        }
    } catch (Throwable e) {
        f.b("getLocation", "getLocation>>>", e);
    }
    return "";
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:26,代碼來源:Util.java

示例4: 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

示例5: onPostCreate

import android.location.Criteria; //導入方法依賴的package包/類
@Override
protected void onPostCreate(Bundle savedInstanceState) {
	super.onPostCreate(savedInstanceState);
	setContentView(R.layout.activity_location);

	tv_location = (TextView) findViewById(R.id.tv_location);

	LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
	Criteria criteria = new Criteria();
	criteria.setCostAllowed(true);
	criteria.setAccuracy(Criteria.ACCURACY_FINE);
	String bestProvider = lm.getBestProvider(criteria, true);

	MyLocationListener myLocationListener = new MyLocationListener();
	lm.requestLocationUpdates(bestProvider, 0, 0, myLocationListener);

}
 
開發者ID:REIGE,項目名稱:AndroidTest,代碼行數:18,代碼來源:activity_location.java

示例6: 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

示例7: 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

示例8: onCreate

import android.location.Criteria; //導入方法依賴的package包/類
@Override
public void onCreate() {
	super.onCreate();
	//��ȡ�ֻ��ľ�γ������
	//1,��ȡλ�ù����߶���
	LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
	//2,�����ŵķ�ʽ��ȡ��γ������()
	Criteria criteria = new Criteria();
	//������
	criteria.setCostAllowed(true);
	criteria.setAccuracy(Criteria.ACCURACY_FINE);//ָ����ȡ��γ�ȵľ�ȷ��
	String bestProvider = lm.getBestProvider(criteria, true);
	//3,��һ��ʱ����,�ƶ�һ��������ȡ��γ������
	MyLocationListener myLocationListener = new MyLocationListener();
	lm.requestLocationUpdates(bestProvider, 0, 0, myLocationListener);
}
 
開發者ID:cckevincyh,項目名稱:mobilesafe,代碼行數:17,代碼來源:LocationService.java

示例9: onCreate

import android.location.Criteria; //導入方法依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();
    manager = (LocationManager) getSystemService(LOCATION_SERVICE);
    listener = new MyListener();
    //criteria 查詢條件
    //true 隻返回可用的位置提供者
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);//獲取精確的位置
    criteria.setCostAllowed(true);//允許產生開銷
    String name = manager.getBestProvider(criteria, true);
    System.out.println("最好的位置提供者:" + name);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }
    manager.requestLocationUpdates(name, 0, 0, listener);
}
 
開發者ID:sh2zqp,項目名稱:MobilePhoneSafeProtector,代碼行數:26,代碼來源:GPSLocationService.java

示例10: onCreate

import android.location.Criteria; //導入方法依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();

    // locate
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    // check permission
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        return;
    }

    // get best provider
    Criteria criteria = new Criteria();
    criteria.setCostAllowed(true);
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    String bestProvider = locationManager.getBestProvider(criteria, true);
    System.out.println("best provider:" + bestProvider);
    // start listening
    listener = new MyLocationListener();
    locationManager.requestLocationUpdates(bestProvider, 0, 0, listener);
}
 
開發者ID:ittianyu,項目名稱:MobileGuard,代碼行數:22,代碼來源:GpsTraceService.java

示例11: 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

示例12: 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

示例13: GeoLocation

import android.location.Criteria; //導入方法依賴的package包/類
/**
 * The constructor of the GeoLocation class and we supplied the Context as a parameter.
 * initialize the application context. Criteria class indicating the application criteria for
 * selecting a location provider. locationManager class provides access to the system location
 * services. These services allow applications to obtain periodic updates of the device's
 * geographical location
 */

public GeoLocation(Context ctx) {
    context = ctx;
    locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        gpsStatus = false;
        return;
    } else {
        gpsStatus = true;
    }
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setCostAllowed(true);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    provider = locationManager.getBestProvider(criteria, true);
    locationManager.requestLocationUpdates(provider, 5000, 0, this);
}
 
開發者ID:egovernments,項目名稱:egov-mobile,代碼行數:27,代碼來源:GeoLocation.java

示例14: getBestProvider

import android.location.Criteria; //導入方法依賴的package包/類
/**
 * 獲取以下條件下,最合適的provider
 */
private void getBestProvider() {
    Criteria criteria = new Criteria();
    // 精度高
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    // 低消耗
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    // 海拔
    criteria.setAltitudeRequired(true);
    // 速度
    criteria.setSpeedRequired(true);
    // 費用
    criteria.setCostAllowed(false);
    String provider = locationManager.getBestProvider(criteria, false); //false是指不管當前適配器是否可用
    this.bestProviderTV.setText(provider);
}
 
開發者ID:CaMnter,項目名稱:AndroidLife,代碼行數:19,代碼來源:LocationManagerActivity.java

示例15: 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


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