跳转 AccessibilityService 设置页面

引导用户开启 AccessibilityService 权限,跳转到无障碍设置页面高亮显示自己的 Service item:


val EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
val EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":settings:show_fragment_args";


startActivity(Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS).apply {
    val bundle = Bundle()
    val componentName = ComponentName(BuildConfig.APPLICATION_ID, AccessibilityServiceName::class.java.name).flattenToString()
    bundle.putString(EXTRA_FRAGMENT_ARG_KEY, componentName)
    putExtra(EXTRA_FRAGMENT_ARG_KEY, componentName)
    putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, bundle)
})

设置完成后返回自己的 Activity :

context?.registerReceiver(returnReceiver,IntentFilter("accessibility_start"))
    

private val returnReceiver = object: BroadcastReceiver() {
    override fun onReceive(context: Context?, intent: Intent) {
        context?.unregisterReceiverOpt(this)
        try {
            startActivity(Intent(context, SettingsActivity::class.java).apply {
                flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
            })
        }catch (e: RuntimeException){
        }
    }
}

 

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页