本文整理汇总了Java中com.google.android.gms.location.LocationAvailability类的典型用法代码示例。如果您正苦于以下问题:Java LocationAvailability类的具体用法?Java LocationAvailability怎么用?Java LocationAvailability使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocationAvailability类属于com.google.android.gms.location包,在下文中一共展示了LocationAvailability类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestLocationAvailabilityUpdates
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
@NonNull
@RequiresPermission(
anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission" +
".ACCESS_FINE_LOCATION"}
)
public Observable<LocationAvailability> requestLocationAvailabilityUpdates(LocationRequest
request) {
return ObservableTask.create(callback -> {
LocationCallback resultCallback = new LocationCallback() {
@Override
public void onLocationAvailability(LocationAvailability locationAvailability) {
super.onLocationAvailability(locationAvailability);
callback.onNext(locationAvailability);
}
};
callback.setDisposeListener(() -> client.removeLocationUpdates(resultCallback));
return client.requestLocationUpdates(request, resultCallback, null);
});
}
示例2: SendLocation
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
public void SendLocation(){
try {
LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient);
if (locationAvailability.isLocationAvailable()) {
// Call Location Services
LocationRequest locationRequest = new LocationRequest()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(10000)//10second
.setFastestInterval(5000);//5second
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
Log.v("SendLocation",locationAvailability.toString());
} else {
// Do something when Location Provider not available
Toast.makeText(getApplicationContext()
, "Please Open Location Provider"
, Toast.LENGTH_SHORT).show();
}
}
catch (Exception e){
Log.v("SendLocation exception",e.toString());
}
}
示例3: onGoogleApiClientReady
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, SingleEmitter<Boolean> emitter) {
//noinspection MissingPermission
LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(apiClient);
if (locationAvailability != null) {
emitter.onSuccess(locationAvailability.isLocationAvailable());
} else {
emitter.onSuccess(false);
}
}
开发者ID:TechIsFun,项目名称:RxJava2-weather-example,代码行数:12,代码来源:LocationAvailabilitySingleOnSubscribe.java
示例4: getLocationAvailability
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
@NonNull
@RequiresPermission(
anyOf = {"android.permission.ACCESS_COARSE_LOCATION", "android.permission" +
".ACCESS_FINE_LOCATION"}
)
public Maybe<LocationAvailability> getLocationAvailability() {
return MaybeTask.create(() -> client.getLocationAvailability());
}
示例5: run
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
@SuppressLint("MissingPermission")
@Override
protected Task<Void> run(ObservableTaskCallback<LocationAvailability> callback) {
ResultCallback resultCallback = new ResultCallback(callback);
callback.setDisposeListener(() -> client.removeLocationUpdates(resultCallback));
return client.requestLocationUpdates(this.request, resultCallback, null);
}
示例6: checkLocationAvailability
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
private boolean checkLocationAvailability() {
if (!googleApiClient.isConnected() || !permissionGranted) return false;
try {
LocationAvailability la = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient);
return (la != null && la.isLocationAvailable());
} catch (SecurityException e) {
if (!quiet)
Log.e(getClass().getSimpleName(), "Error while checking location availability:\n " + e.toString());
if (listener != null)
listener.onError(ErrorType.RETRIEVAL, "Could not check location availability:\n" +
e.getMessage());
return false;
}
}
示例7: handleMessage
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
public final void handleMessage(Message paramMessage)
{
switch (paramMessage.what)
{
default:
return;
case 0:
this.a.a((LocationResult)paramMessage.obj);
return;
}
this.a.a((LocationAvailability)paramMessage.obj);
}
示例8: onConnected
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
@Override
public void onConnected(final Bundle bundle) {
if (! mGoogleApiClient.isConnected()) {
Log.w("OpenLocationCodes", "GoogleApiClient was disconnected");
return;
}
if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_DENIED) {
// TODO
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull final Status status) {
if (status.isSuccess()) {
Log.d("OpenLocationCodes", "LocationServices: SUCCESS");
final LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(mGoogleApiClient);
if (locationAvailability != null && locationAvailability.isLocationAvailable()) {
onLocationChanged(LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient));
}
} else if (status.isCanceled()) {
Log.d("OpenLocationCodes", "LocationServices: CANCELED");
} else if (status.isInterrupted()) {
Log.d("OpenLocationCodes", "LocationServices: INTERRUPTED");
}
}
});
}
示例9: insertGyroTOserver
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
public void insertGyroTOserver(final String dt,final String x, final String y, final String z)
{
if(lat!=0 || lng!=0) {
try {
LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient);
if (locationAvailability.isLocationAvailable()) {
// Call Location Services
LocationRequest locationRequest = new LocationRequest()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
}
// String queryString = createQueryString(params);
final String SITE_URL = "http://168.63.175.28/addGyro.php";
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
RequestBody formBody = new FormEncodingBuilder()
.add("isAdd", "true")
.add("imei", telephonyManager.getDeviceId())
.add("time",dt)
.add("x", x)
.add("y", y)
.add("z", z)
.add("lat",String.valueOf(lat))
.add("lng",String.valueOf(lng))
.build();
PostForm p= new PostForm(formBody,SITE_URL);
final Toast toast = Toast.makeText(getApplicationContext(), "มีการกระแทกเกิดขึ้น", Toast.LENGTH_SHORT);
// toast.show();
}
catch (Exception ex) {
Log.v("ex", ex.toString());
}
}
}
示例10: Start
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
public void Start(View view){
LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient);
if (locationAvailability.isLocationAvailable()) {
// Call Location Services
LocationRequest locationRequest = new LocationRequest()
.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
} else {
// Do something when Location Provider not available
}
}
示例11: Stop
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
public void Stop(View view){
LocationAvailability locationAvailability = LocationServices.FusedLocationApi.getLocationAvailability(googleApiClient);
if (locationAvailability.isLocationAvailable()) {
// Call Location Services
LocationRequest locationRequest = new LocationRequest()
.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, locationRequest, this);
} else {
// Do something when Location Provider not available
}
}
示例12: onConnected
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
@Override
public void onConnected(Bundle connectionHint) {
Log.i("CaptureActivity", "onConnected called");
clientReady = true;
//Use a new thread to request location updates for the worker thread.
//This new thread waits until the result of the request for updates is complete.
Runnable r = new Runnable(){
@Override
public void run() {
LocationRequest request = new LocationRequest();
request.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setInterval(5000);
LocationCallback locationCallback = new LocationCallback() {
@Override
public void onLocationAvailability(LocationAvailability availability) {
if (!availability.isLocationAvailable()) {
locationReady = false;
}
}
public void onLocationResult(LocationResult result) {
newestLocation = result.getLastLocation();
}
};
PendingResult<Status> requestResult = LocationServices.FusedLocationApi.requestLocationUpdates(googleApiClient, request, locationCallback, handler.getLooper());
Status requestStatus = requestResult.await();
locationReady = true;
if(requestStatus.isSuccess()) {
locationReady = true;
Log.i("CaptureActivity", "Location update request result success!");
}else {
Log.i("CaptureActivity", "Location update request result: failure!");
}
}
};
new Thread(r).start();
}
示例13: onLocationAvailability
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
@Override public void onLocationAvailability(LocationAvailability locationAvailability) {
Log.i("Debug ", "On Location availability");
}
示例14: ResultCallback
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
public ResultCallback(ObservableTaskCallback<LocationAvailability> callback) {
this.callback = callback;
}
示例15: onLocationAvailability
import com.google.android.gms.location.LocationAvailability; //导入依赖的package包/类
public void onLocationAvailability(LocationAvailability result) {
super.onLocationAvailability(result);
callback.onNext(result);
}