Hallo Tüftler,
ich schreibe gerade eine Android-Anwendung, die in regelmäßigen Abständen die GPS-Position an einen Restservice schicken soll. Das ganze funktioniert wunderbar unter Android 7.1, unter Android 11 kommt kein Response vom Server. Die GPS-Position wird gefunden, unter 7.1 und 11. Die Abfrage nach Location und WriteStorage kommt beim Start des Programms
Das ist der JSONRequest:
Code
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.POST, url, jo, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("onResponse", ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "+ response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO: Handle error
}
});
requestQueue.add(jsonObjectRequest);
Alles anzeigen
und dieser Response kommt nicht unter 11, es kommt aber kein Fehler. (das ganze läuft in einem service.
Hier meine manifest:
Code
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-feature
android:name="android.hardware.ethernet"
android:required="false" />
<uses-feature
android:name="android.hardware.location.network"
android:required="false" />
<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
Alles anzeigen
Die Permissions frage ich in der Main ab, von der dann der Service gestartet wird:
Code
private void checkPermissions() {
List<String> permissions = new ArrayList<>();
String message = "osmdroid permissions:";
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
message += "\nLocation to show user location.";
}
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);
message += "\nLocation to show user location.";
}
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.ACCESS_NETWORK_STATE);
message += "\nStorage access to store map tiles.";
}
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_WIFI_STATE) != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.ACCESS_WIFI_STATE);
message += "\nStorage access to store map tiles.";
}
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
message += "\nStorage access to store map tiles.";
}
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
message += "\nStorage access to store map tiles.";
}
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.INTERNET);
message += "\nStorage access to store map tiles.";
}
if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.INTERNET);
message += "\nStorage access to store map tiles.";
}
if (!permissions.isEmpty()) {
//Toast.makeText(getContext(), message, Toast.LENGTH_LONG).show();
String[] params = permissions.toArray(new String[permissions.size()]);
requestPermissions(params, REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS);
} // else: We already have permissions, so handle as normal
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case REQUEST_CODE_ASK_MULTIPLE_PERMISSIONS: {
Map<String, Integer> perms = new HashMap<>();
// Initial
perms.put(Manifest.permission.ACCESS_FINE_LOCATION, PackageManager.PERMISSION_GRANTED);
perms.put(Manifest.permission.ACCESS_COARSE_LOCATION, PackageManager.PERMISSION_GRANTED);
perms.put(Manifest.permission.WRITE_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED);
perms.put(Manifest.permission.READ_EXTERNAL_STORAGE, PackageManager.PERMISSION_GRANTED);
perms.put(Manifest.permission.INTERNET, PackageManager.PERMISSION_GRANTED);
perms.put(Manifest.permission.ACCESS_NETWORK_STATE, PackageManager.PERMISSION_GRANTED);
perms.put(Manifest.permission.ACCESS_WIFI_STATE, PackageManager.PERMISSION_GRANTED);
// Fill with results
for (int i = 0; i < permissions.length; i++)
perms.put(permissions[i], grantResults[i]);
// Check for ACCESS_FINE_LOCATION and WRITE_EXTERNAL_STORAGE
Boolean location = perms.get(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED;
Boolean storage = perms.get(Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
if (location && storage) {
// All Permissions Granted
//Toast.makeText(getContext(), "All permissions granted", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), "All permissions granted", Toast.LENGTH_LONG).show();
} else if (storage) {
Toast.makeText(getApplicationContext(), "Storage permission is required to store map tiles to reduce data usage and for offline usage.", Toast.LENGTH_LONG).show();
} else if (location) {
Toast.makeText(getApplicationContext(), "Location permission is required to show the user's location on map.", Toast.LENGTH_LONG).show();
} else { // !location && !storage case
// Permission Denied
Toast.makeText(getApplicationContext(), "Storage permission is required to store map tiles to reduce data usage and for offline usage." +
"\nLocation permission is required to show the user's location on map.", Toast.LENGTH_SHORT).show();
}
Configuration.getInstance().load(getApplicationContext(), PreferenceManager.getDefaultSharedPreferences(getApplicationContext()));
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
Alles anzeigen
Kann mir jemand helfen?
Gruß
Pfeiffy