2016-08-12 16 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

我仍然無法複製你的想法 –