AccessibilityService自启动

实现AccessibilityService自启动的方法

说明:自定义AccessibilityService时,默认关闭的,需要在无障碍界面手动打开。若需自动打开有两种方法。


1.源码中修改

frameworks\base\packages\SettingsProvider\src\com\android\providers\settings\DatabaseHelper.java 

在loadSecureSettings函数中添加如下代码:
loadSetting(stmt, Settings.Secure.ACCESSIBILITY_ENABLED,1);
loadSetting(stmt, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,

                   "com.gdvictor.victortool/com.gdvictor.victortool.IntelligentUpgrade.MyAccessibilityService");

2.在APP中修改,需要给APP授权系统权限,将APP在源码中编译

在AndroidManiferst.xml中声明权限



在APP启动入口处添加:

Settings.Secure.putString(getContentResolver(),
                Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
                "com.gdvictor.victortool/com.gdvictor.victortool.IntelligentUpgrade.MyAccessibilityService");
Settings.Secure.putInt(getContentResolver(),
                Settings.Secure.ACCESSIBILITY_ENABLED, 1);



你可能感兴趣的:(Android源码)