获取其他用户的UID Firebase android

时间:2017-07-16 09:15:01

标签: android firebase firebase-realtime-database firebase-authentication firebase-cloud-messaging

我正面临有关UID的问题 我是UIDs一个是客户,另一个是司机,如下图所示

Database Image

我想做的是当客户点击然后通知发送给他接受后的驱动程序,我得到坐标 我不是firebase的专家 有getcurrentuser的方法,但我想获得驱动程序uid。 我怎么得到这个? 我搜索了通知。 我想以编程方式发送它而不是从控制台发送它。大多数教程都会从控制台发送通知。我想通过按钮发送。

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);

   currentFirebaseUser= FirebaseAuth.getInstance().getCurrentUser();
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    mo = new MarkerOptions().position(new LatLng(0, 0)).title("My Current Location");
    set_long_lat = new LongtitudeLatitude();
    databaseReference = FirebaseDatabase.getInstance().getReference(Constants.FDATABASE);
    go=(FloatingActionButton)findViewById(R.id.floatingActionButton);



    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);


    if (Build.VERSION.SDK_INT >= 23 && !isPermissionGranted()) {
        requestPermissions(PERMISSIONS, PERMISSION_ALL);
    } else requestLocation();
    if (!isLocationEnabled())
        showAlert(1);
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    marker =  mMap.addMarker(mo);
}

@Override
public void onLocationChanged(Location location) {

    latitude=location.getLatitude();
    longitude=location.getLongitude();

    LatLng myCoordinates = new LatLng(latitude,longitude);
    marker.setPosition(myCoordinates);
    mMap.moveCamera(CameraUpdateFactory.newLatLng(myCoordinates));
    if (latitude!=null&&longitude!=null)
    {
        set_long_lat.setLat(latitude);
        set_long_lat.setLng(longitude);
        databaseReference.child(currentFirebaseUser.getUid()).setValue(set_long_lat);

    }



}

@Override
public void onStatusChanged(String s, int i, Bundle bundle) {

}

@Override
public void onProviderEnabled(String s) {

}

@Override
public void onProviderDisabled(String s) {

}

private void requestLocation() {
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.POWER_HIGH);
    String provider = locationManager.getBestProvider(criteria, true);
    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;
    }
    locationManager.requestLocationUpdates(provider, 1000, 0, this);
}
private boolean isLocationEnabled() {
    return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) ||
            locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
}

@RequiresApi(api = Build.VERSION_CODES.M)
private boolean isPermissionGranted() {
    if (checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION)
            == PackageManager.PERMISSION_GRANTED || checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
        Log.v("mylog", "Permission is granted");
        return true;
    } else {
        Log.v("mylog", "Permission not granted");
        return false;
    }
}
private void showAlert(final int status) {
    String message, title, btnText;
    if (status == 1) {
        message = "Your Locations Settings is set to 'Off'.\nPlease Enable Location to " +
                "use this app";
        title = "Enable Location";
        btnText = "Location Settings";
    } else {
        message = "Please allow this app to access location!";
        title = "Permission access";
        btnText = "Grant";
    }
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setCancelable(false);
    dialog.setTitle(title)
            .setMessage(message)
            .setPositiveButton(btnText, new DialogInterface.OnClickListener() {
                @RequiresApi(api = Build.VERSION_CODES.M)
                @Override
                public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                    if (status == 1) {
                        Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        startActivity(myIntent);
                    } else
                        requestPermissions(PERMISSIONS, PERMISSION_ALL);
                }
            })
            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                    finish();
                }
            });
    dialog.show();
}

} 通过浮动按钮,我想以编程方式发送通知并获取驱动程序的UID

1 个答案:

答案 0 :(得分:-1)

我担心这是不可能的,因为Firebase安全策略不允许您检索其他用户,除非您将它们存储在数据库中以使用它们。