Created
December 12, 2020 14:43
-
-
Save mhrpatel12/b49f49261d2eae23f33bebbcba99b424 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun isAccessibilityServiceEnabled(mContext: Context): Boolean { | |
var accessibilityEnabled = 0 | |
val service: String = mContext.packageName + "/" + YourAccessibilityService::class.java.canonicalName | |
try { | |
accessibilityEnabled = Settings.Secure.getInt( | |
mContext.applicationContext.contentResolver, | |
Settings.Secure.ACCESSIBILITY_ENABLED | |
) | |
Log.v(TAG, "accessibilityEnabled = $accessibilityEnabled") | |
} catch (e: Settings.SettingNotFoundException) { | |
Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.message) | |
} | |
val mStringColonSplitter = SimpleStringSplitter(':') | |
if (accessibilityEnabled == 1) { | |
Log.v(TAG, "Accessibility Is Enabled") | |
val settingValue: String = Settings.Secure.getString( | |
mContext.applicationContext.contentResolver, | |
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES | |
) | |
if (settingValue != null) { | |
mStringColonSplitter.setString(settingValue) | |
while (mStringColonSplitter.hasNext()) { | |
val accessibilityService = mStringColonSplitter.next() | |
Log.v(TAG, "AccessibilityService :: $accessibilityService $service") | |
if (accessibilityService.equals(service, ignoreCase = true)) { | |
Log.v(TAG, "accessibility is switched on!") | |
return true | |
} | |
} | |
} | |
} else { | |
Log.v(TAG, "accessibility is disabled") | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment