mirror of
https://codeberg.org/NextPush/nextpush-android.git
synced 2024-12-26 09:42:39 +01:00
Fix permission for SDK<26
This commit is contained in:
parent
94cd3badba
commit
1d206c92f8
@ -8,6 +8,7 @@ import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import org.unifiedpush.distributor.nextpush.R
|
||||
import org.unifiedpush.distributor.nextpush.activities.PermissionsRequest.requestAppPermissions
|
||||
import org.unifiedpush.distributor.nextpush.utils.TAG
|
||||
|
||||
object PermissionsRequest {
|
||||
@ -35,6 +36,33 @@ object PermissionsRequest {
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
)
|
||||
}
|
||||
} else if (Build.VERSION.SDK_INT < 26) {
|
||||
this.requestAccountPermission()
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("For SDK<26 only")
|
||||
fun AppCompatActivity.requestAccountPermission() {
|
||||
if (checkSelfPermission(Manifest.permission.GET_ACCOUNTS)
|
||||
!= PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
Log.d(TAG, "Requesting GET_ACCOUNT permission")
|
||||
this.registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission()
|
||||
) { granted ->
|
||||
Log.d(TAG, "GET_ACCOUNT permission granted: $granted")
|
||||
if (!granted) {
|
||||
if (shouldShowRequestPermissionRationale(Manifest.permission.GET_ACCOUNTS)) {
|
||||
Log.d(TAG, "Show GET_ACCOUNTS permission rationale")
|
||||
AlertDialog.Builder(this)
|
||||
.setTitle(getString(R.string.no_notification_dialog_title))
|
||||
.setMessage(R.string.no_notification_dialog_message)
|
||||
.show()
|
||||
}
|
||||
}
|
||||
}.launch(
|
||||
Manifest.permission.GET_ACCOUNTS
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user