阻止
Android的所有对话框,这意味着在我的服务运行之前,应用程序或Android系统都不会出现任何对话框.有没有办法以编程方式进行?
解决方法
我不认为可以阻止所有弹出窗口.
@H_403_6@对我而言,android通常不允许这样做.
@H_403_6@但你可以尝试(如果你真的想:))使你的应用程序成为Accessibility Service,它将对弹出窗口作出反应并立即关闭它.要关闭弹出窗口,您可以在其上找到一些取消按钮并执行click或performGlobalAction(GLOBAL_ACTION_BACK); (如果可以取消).
@H_403_6@在这里查看一些代码来找到一个弹出窗口:Android unable read window content on few devices using accessibility service(我不知道是否可行)
@H_403_6@您还可以查看此内容,以获取有关如何使用辅助功能服务查找视图和点击任何应用的更多灵感:Programmatically enabling/disabling accessibility settings on Android device
@H_403_6@编辑:更多细节
@H_403_6@您需要按照此标准教程将该服务添加到您的应用程序:https://developer.android.com/training/accessibility/service.html
@H_403_6@首先要注意的是,您应该决定使用xml配置并在教程中包含android:canRetrieveWindowContent =“true”:
<accessibility-service android:accessibilityEventTypes="typeViewClicked|typeViewFocused" android:packageNames="com.example.android.myFirstApp,com.example.android.mySecondApp" android:accessibilityFeedbackType="FeedbackSpoken" android:notificationTimeout="100" android:settingsActivity="com.example.android.apis.accessibility.TestBackActivity" android:canRetrieveWindowContent="true" />@H_403_6@我认为你不需要行android:packageName @H_403_6@然后你需要试验回调方法中应该发生什么 – 这只是我粗略的建议:
@Override public void onAccessibilityEvent(AccessibilityEvent event) { AccessibilityNodeInfo source = event.getSource(); if(event.getEventType()==AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) if(isAlert(source)) //explore the view (maybe recursively) to find if there is an alert performGlobalAction(GLOBAL_ACTION_BACK); }@H_403_6@并且递归方法可以是
private boolean isAlert(AccessibilityNodeInfo view){ int count = view.getChildCount(); boolean result = false; for(int i=0; i<count; i++){ AccessibilityNodeInfo child = view.getChild(i); if(child.getClassName().contains("Alert")){ return true; } if (explore(child)); result = true; child.recycle(); return result; }