Ich versuche, um eine Erlaubnis auf meinem Service zu bitten. Normalerweise muss ich eine Aktivität übergeben, um eine Erlaubnis zu erhalten. Meine Anwendung hat keine Activity
.So fordern Sie eine Erlaubnis von einem Service an
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
// Show an explanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
}
}
Wie kann ich es von einem Service aus tun?
Wieso wurde ich abgelehnt? Dies ist eine gültige Frage. Bitte erkläre, wenn ich falsch liege, werde ich gerne meine Frage entfernen. –