Android: programmatically open Overview/Recents screen in API 24+

后端 未结 1 1058
执笔经年
执笔经年 2021-01-12 17:35

I am trying to open the Overview/Recents screen in Android. From Android: Programmatically open "Recent Apps" dialog, I can use the following code:



        
1条回答
  •  别那么骄傲
    2021-01-12 18:25

    Create service extended from AccessibilityService:

    class ExampleAccessService:AccessibilityService() {
        override fun onInterrupt() {
        }
    
        override fun onAccessibilityEvent(event: AccessibilityEvent?) {
        }
    
        fun doAction(){
            performGlobalAction(GLOBAL_ACTION_RECENTS)
    //        performGlobalAction(GLOBAL_ACTION_BACK)
    //        performGlobalAction(GLOBAL_ACTION_HOME)
    //        performGlobalAction(GLOBAL_ACTION_NOTIFICATIONS)
    //        performGlobalAction(GLOBAL_ACTION_POWER_DIALOG)
    //        performGlobalAction(GLOBAL_ACTION_QUICK_SETTINGS)
    //        performGlobalAction(GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN)
        }
    }
    

    Call doAction() where you want action

    Add to Manifest:

    Accessibility->Services
            android:enabled="true"
            android:exported="false" >
            
                
            
            
        
    ...
    
    

    accessibility_service_config.xml:

    
    
    

    for more info look at https://developer.android.com/guide/topics/ui/accessibility/services.html

    0 讨论(0)
提交回复
热议问题