Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object AccessProvider {
- // Method to check if device admin is enabled
- fun checkAdminAccess(activity: FragmentActivity?, devicePolicyManager: DevicePolicyManager): Boolean {
- val compName = ComponentName(context!!, DeviceAdmin::class.java)
- if (devicePolicyManager.isAdminActive(compName)) {
- return true
- } else {
- val intent = Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN)
- intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName);
- intent.putExtra(
- DevicePolicyManager.EXTRA_ADD_EXPLANATION,
- "You should enable the app!"
- )
- activity!!.startActivityForResult(intent, 1)
- }
- return false
- }
- // Method to check notification policies access status
- fun checkNotificationPolicyAccess(notificationManager: NotificationManager): Boolean {
- if (notificationManager.isNotificationPolicyAccessGranted) {
- return true
- } else {
- Toast.makeText(
- context,
- "You need to grant notification policies access.",
- Toast.LENGTH_SHORT
- ).show()
- val intent = Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS)
- startActivity(intent)
- }
- return false
- }
- // Method to check the permission to write system settings
- fun checkWriteSystemSettingsAccess(): Boolean {
- if (Settings.System.canWrite(context)) {
- return true
- } else {
- val intent = Intent(
- Settings.ACTION_MANAGE_WRITE_SETTINGS,
- Uri.parse("package:" + activity!!.packageName)
- )
- startActivity(intent)
- }
- return false
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement