Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. object AccessProvider {
  2.  
  3. // Method to check if device admin is enabled
  4. fun checkAdminAccess(activity: FragmentActivity?, devicePolicyManager: DevicePolicyManager): Boolean {
  5. val compName = ComponentName(context!!, DeviceAdmin::class.java)
  6. if (devicePolicyManager.isAdminActive(compName)) {
  7. return true
  8. } else {
  9. val intent = Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN)
  10. intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName);
  11. intent.putExtra(
  12. DevicePolicyManager.EXTRA_ADD_EXPLANATION,
  13. "You should enable the app!"
  14. )
  15. activity!!.startActivityForResult(intent, 1)
  16. }
  17. return false
  18. }
  19.  
  20. // Method to check notification policies access status
  21. fun checkNotificationPolicyAccess(notificationManager: NotificationManager): Boolean {
  22. if (notificationManager.isNotificationPolicyAccessGranted) {
  23. return true
  24. } else {
  25. Toast.makeText(
  26. context,
  27. "You need to grant notification policies access.",
  28. Toast.LENGTH_SHORT
  29. ).show()
  30. val intent = Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS)
  31. startActivity(intent)
  32. }
  33. return false
  34. }
  35.  
  36. // Method to check the permission to write system settings
  37. fun checkWriteSystemSettingsAccess(): Boolean {
  38. if (Settings.System.canWrite(context)) {
  39. return true
  40. } else {
  41. val intent = Intent(
  42. Settings.ACTION_MANAGE_WRITE_SETTINGS,
  43. Uri.parse("package:" + activity!!.packageName)
  44. )
  45. startActivity(intent)
  46. }
  47. return false
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement