IOS正在将请求发送到Android驱动程序...
使用(glomadrian.materialanimatedswitch)MaterialAnimatedSwitch,当我切换到在线状态时,它会很好用。但是,如果交换机处于在线状态,并且说有骑手要求乘车,则什么也不会发生。
location_switch
location_switch.setOnCheckedChangeListener(new MaterialAnimatedSwitch.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(boolean isOnline) {
if (isOnline) {
// set connected when switched to on
getInstance().goOnline();
iosRiderRequest(); // if runs, intents to acceptance activity
if (ActivityCompat.checkSelfPermission(DriverHome.this, Manifest.permission.
ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat
.checkSelfPermission(DriverHome.this, Manifest.permission
.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
return;
}
buildLocationCallBack();
buildLocationRequest();
fusedLocationProviderClient.requestLocationUpdates(mLocationRequest,
locationCallback, Looper.myLooper());
displayLocation();
Log.e(TAG, "displayLocation1");
Snackbar.make(mapFragment.getView(), "You are online", Snackbar
.LENGTH_SHORT).show();
btnFindUser.setText("Slide Switch to go OFFLINE");
} else {
// set disconnected when switched to off
onlineDriverRef.removeValue(); // remove 'DriversOnline'
getInstance().goOffline();
fusedLocationProviderClient.removeLocationUpdates(locationCallback);
map.clear();
// handler.removeCallbacks(drawPathRunnable); // if enabled, causes error
if (handler != null)
handler.removeCallbacks(drawPathRunnable);
Snackbar.make(mapFragment.getView(), "You are offline", Snackbar
.LENGTH_SHORT).show();
btnFindUser.setText("Slide Switch to go ONLINE");
}
}
});
如果请求是在驾驶员上线之前发出的,并且一旦他/她上线,则驾驶员会看到该请求,但是如果驾驶员正在在线等待请求,并且驾驶员提出了请求,则驾驶员不会看到该请求。驱动程序。
我尝试了此操作,但不起作用(在onCreate中):
final DatabaseReference rideRequests = FirebaseDatabase.getInstance().getReference("RideRequests");
rideRequests.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
riderId = ds.getKey();
rideRequests.child(riderId).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot.child("isIOSRider").exists()) {
isIOSRider = true;
Log.e(TAG, "isIOSRider = " + isIOSRider);
iosRiderRequest();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});