得到其他用户的Android火力地堡

问题描述:

我就面临一个问题,UID UID 我有2 UIDs一个是客户和其他司机是中所示PIC下面得到其他用户的Android火力地堡

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

+0

您将不得不开发一个脚本,该脚本将接收坐标并将其作为通知发送给驱动程序。阅读本指南:https://firebase.google.com/docs/cloud-messaging/server#implementing-the-http-server-protocol,将用户UID /详细信息存储在数据库中 – Manny265

+0

@ Manny265您会为此发送教程吗? –

+0

我已包含的链接将帮助您以编程方式发送通知。至于用户和UID,我建议你将它们存储在一个数据库中,并能够分辨哪一个是驱动程序和客户端。你的代码在哪里? – Manny265

恐怕,这是不可能的,因为火力地堡的安全策略不允许您检索其他用户,除非你将它们存储在数据库中以使用它们。

+0

不要说这个! :(这是为我做的或死的项目! –

+0

我建议您将驱动程序和骑手的UID保存在Firebase数据库中,以便您不需要直接查询UID,而且这是最安全的方式。 –