在速度计应用程序中,如何将变化的速度包含在数组中的location.getSpeed()
函数中,以便可以使用math.max
函数找到最高的速度?
public class Main3Activity extends AppCompatActivity implements
android.location.LocationListener {
int arr[];
private float [] speeds=new float[10];
public float boo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
LocationManager lm =
(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
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;
}
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,this);
this.onLocationChanged(null);
final TextView mTextField=(TextView)this.findViewById(R.id.textView);
new CountDownTimer(11000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("" + millisUntilFinished / 1000);
}
public void onFinish() {
Intent myIntent = new Intent(Main3Activity.this,
aftergame.class);
startActivity(myIntent);
}
}.start();
}
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case 1: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
public boolean checkLocationPermission()
{
String permission = "android.permission.ACCESS_FINE_LOCATION";
int res = this.checkCallingOrSelfPermission(permission);
return (res == PackageManager.PERMISSION_GRANTED);
}
@Override
public void onLocationChanged(Location location) {
int cpeedi;
TextView txt=(TextView)this.findViewById(R.id.st);
if(location==null){
txt.setText("0 m/s");
}else{
float cpeed=location.getSpeed();
float cpeed1=location.getSpeed();
cpeedi=(int)cpeed;
txt.setText(cpeedi + " m/s");
}
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}