Ich entwickle eine Transit-Wand-Anwendung, die Buslinien und Passagierhaltestellen erfasst und diese dann aufzeichnet. Muss ich die Standortberechtigung im Hintergrund verwenden? Ich fordere Standortaktualisierungen in einem Dienst an und verwende zu diesem Zweck den Fused Location Provider.
In MainActivity (Anfrage-Berechtigung)
@SuppressLint("MissingPermission")
public void getCurrentLocation(OnSuccessListener successListener, OnFailureListener failureListener) {
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
fusedLocationProviderClient.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, cancellationTokenSource.getToken())
.addOnSuccessListener(successListener)
.addOnFailureListener(failureListener);
}
public void onLocationChanged(Location location) {
Log.i("LOCATION", "onLocationChanged");
///POINTS RECORDED EVERY 5 METERS
if (currentCapture != null && location.getAccuracy() < 15 * 2) {
RoutePoint rp = new RoutePoint();
rp.location = location;
rp.time = SystemClock.elapsedRealtime();
currentCapture.points.add(rp);
if (lastLocation != null) {
currentCapture.distance += distanceFromLocation(lastLocation, location);
if (iCaptureActivity != null) {
iCaptureActivity.updateDistance();
}
}
lastLocation = location;
if (iCaptureActivity != null) {
iCaptureActivity.updateGpsStatus();
}
} else {
Log.e("Unable to update Location", "Unable to update Location");
}
}
@SuppressLint("MissingPermission")
public void startLocationTracking() {
fusedLocationProviderClient.requestLocationUpdates(locationRequest, locationCallback, Looper.getMainLooper())
.addOnSuccessListener(aVoid -> Log.i("Location", "All Ok"))
.addOnFailureListener(e -> Log.e("Location", "Error", e));
}
public void stopLocationTracking() {
fusedLocationProviderClient.removeLocationUpdates(locationCallback);
}
public void initLocation() {
Log.w("CaptureService", "initLocation");
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
locationRequest = new LocationRequest.Builder(10 * 1000L)
.setMinUpdateDistanceMeters(5) /// change later to 5
.setWaitForAccurateLocation(true)
.setPriority(Priority.PRIORITY_HIGH_ACCURACY)
.build();
locationCallback = new LocationCallback() {
@Override
public void onLocationResult(@NonNull LocationResult locationResult) {
super.onLocationResult(locationResult);
CaptureService.this.onLocationChanged(locationResult.getLastLocation());
Log.w("initLocation Event", String.valueOf(locationResult.getLastLocation()));
}
};
}
public String getGpsStatus() {
String status = "";
if(lastLocation != null)
status = "GPS +/-" + Math.round(lastLocation.getAccuracy()) + "m";
else
status = "GPS Pending";
return status;
}
Google stellt hohe Ansprüche an diese Erlaubnis und ich muss erklären, warum ich sie verwenden muss. Welche Vorteile bringt es für meine App, wenn ich sie nutze? Oder kann der feine Standortzugriff diese Aufgabe standardmäßig übernehmen, beispielsweise wenn der Bildschirm gesperrt ist oder die Anwendung nicht geöffnet ist, sondern zusammen mit anderen Apps ausgeführt wird? Bitte erläutern Sie dies genauer
Ich entwickle eine Transit-Wand-Anwendung, die Buslinien und Passagierhaltestellen erfasst und diese dann aufzeichnet. Muss ich die Standortberechtigung im Hintergrund verwenden? Ich fordere Standortaktualisierungen in einem Dienst an und verwende zu diesem Zweck den Fused Location Provider. In MainActivity (Anfrage-Berechtigung) [code]private void askForForegroundLocationPermission(Runnable backgroundPermission) {
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.ACCESS_BACKGROUND_LOCATION)) {
new AlertDialog.Builder(this) .setTitle("Permission Needed!") .setMessage("Background Location Permission Needed!") .setPositiveButton("OK", (dialog, which) -> ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION}, BACKGROUND_LOCATION_PERMISSION_CODE)) .setNegativeButton("CANCEL", null) .create().show();
} else {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{ Manifest.permission.ACCESS_BACKGROUND_LOCATION}, BACKGROUND_LOCATION_PERMISSION_CODE);
}
}
}
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == FOREGROUND_LOCATION_PERMISSION_CODE) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { askForBackgroundLocationPermission(); } } } } [/code] CaptureService – Teile, die für die Durchführung von Standortprüfungen verantwortlich sind. [code] @SuppressLint("MissingPermission") public void getCurrentLocation(OnSuccessListener successListener, OnFailureListener failureListener) {
CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
public void stopLocationTracking() { fusedLocationProviderClient.removeLocationUpdates(locationCallback); }
public void initLocation() {
Log.w("CaptureService", "initLocation");
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this); locationRequest = new LocationRequest.Builder(10 * 1000L) .setMinUpdateDistanceMeters(5) /// change later to 5 .setWaitForAccurateLocation(true) .setPriority(Priority.PRIORITY_HIGH_ACCURACY) .build(); locationCallback = new LocationCallback() { @Override public void onLocationResult(@NonNull LocationResult locationResult) { super.onLocationResult(locationResult); CaptureService.this.onLocationChanged(locationResult.getLastLocation()); Log.w("initLocation Event", String.valueOf(locationResult.getLastLocation())); } };
}
public String getGpsStatus() {
String status = "";
if(lastLocation != null) status = "GPS +/-" + Math.round(lastLocation.getAccuracy()) + "m"; else status = "GPS Pending";
return status; } [/code] Google stellt hohe Ansprüche an diese Erlaubnis und ich muss erklären, warum ich sie verwenden muss. Welche Vorteile bringt es für meine App, wenn ich sie nutze? Oder kann der feine Standortzugriff diese Aufgabe standardmäßig übernehmen, beispielsweise wenn der Bildschirm gesperrt ist oder die Anwendung nicht geöffnet ist, sondern zusammen mit anderen Apps ausgeführt wird? Bitte erläutern Sie dies genauer [code]
In meiner Deep-Learning-Übung musste ich einen Parameter D1 mit der gleichen Größe wie A1 initialisieren, also habe ich Folgendes getan:
D1 = np.random.randn(A1.shape ,A1.shape )
Ich arbeite an einer Java-Anwendung, bei der Schlüsselpaare gespeichert und abgerufen werden. /> Such- und Insertionsleistung
Anwendungsfälle, in denen eine gegenüber den anderen bevorzugt wird.
Ich habe gelernt, dass isset($array) nicht erforderlich ist, wenn die Existenz eines bestimmten Schlüssels überprüft wird. Ich weiß jedoch auch, dass es einige Gründe gibt, ohne bekannten Schlüssel...
Ich versuche, den Unterschied zwischen der Verwendung eines generischen Typparameters und einer Wildcard in Java -Generika zu verstehen.public static void print(List list)
Ich versuche, den Unterschied zwischen der Verwendung eines generischen Typparameters und einer Wildcard in Java -Generika zu verstehen. public static void print(List list)