2016-08-12 69 views

回答

0

我不认为有可能阻止所有弹出窗口。

对我来说它是有道理的,Android不允许这样做。

但是,你可以尝试(如果你真的想:))使你的应用程序Accessibility Service这将弹出显示,并立即关闭它作出反应。要关闭弹出窗口,您可以在上面找到一些取消按钮并执行点击或performGlobalAction(GLOBAL_ACTION_BACK);(如果它可取消)。

检查出一些代码在这里找到一个弹出:Android unable read window content on few devices using accessibility service(我不知道这是否会工作)

您还可以查看此获得关于如何取景一些更多的灵感和制作点击使用辅助服务的任何应用程序:Programmatically enabling/disabling accessibility settings on Android device


编辑:更多的细节

您需要按照这个标准教程添加SERVIC E要你的应用程序:https://developer.android.com/training/accessibility/service.html

首先要注意的是,你应该决定使用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" 
/> 

,我想你不会需要行android:packageName

然后,你需要在实验回调方法应该发生什么 - 这里只是我粗略的建议:

@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); 
} 

和递归方法可以像

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; 
} 
+0

你能否提供一些样板/或帮助代码这样做,因为我不出来呢 –

+0

OK,我只是快速添加一些代码,使我你的问题的想法。 – Tom

+0

我仍然无法复制你的想法 –