2016-05-24 3 views
1

Я хочу открыть браузер по умолчанию в Android, когда какой-либо код javascript выполняет «window.open()» в веб-браузере.Пересечение: XWalkUIClient.onCreateWindowRequested(): Как получить требуемый URL?

Я создал класс, который расширяет XWalkUIClient и переопределяет onCreateWindowRequested(). Этот метод вызывается при вызове window.open(), который является желаемым. Тем не менее, я не знаю, как получить параметр url, с которым вызван window.open(). Кто-нибудь знает, как я могу получить URL-адрес?

После того, как я получаю URL, я хочу, чтобы открыть этот URL с помощью следующего кода:

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));

ответ

1

Вы не можете получить доступ к URL напрямую, но с временным XWalkView и обычай XWalkUIClient в onCreateWindowRequested, вы может достичь того, что вам нужно.

В следующем примере кода показано, как получить доступ к URL в onCreateWindowRequested:

xWalkView.setUIClient(new XWalkUIClient(xWalkView) { 
    @Override 
    public boolean onCreateWindowRequested(XWalkView view, InitiateBy initiator, final ValueCallback<XWalkView> callback) { 
     // Create a temporary XWalkView instance and set a custom XWalkUIClient 
     // to it with the setUIClient method. The url is passed as a parameter to the 
     // XWalkUIClient.onPageLoadStarted method. 
     XWalkView tempView = new XWalkView(getActivity()); 
     tempView.setUIClient(new XWalkUIClient(tempView) { 
      @Override 
      public void onPageLoadStarted(XWalkView view, String url) { 
       Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
       startActivity(intent); 
      } 
     }); 

     // Return the temporary XWalkView instance with the callback to start the page 
     // load process in tempView. 
     callback.onReceiveValue(tempView); 
     return true; 
    } 
}); 
+0

Привет, какая версия пешеходном вы используете в вашем примере? – Vall0n

Смежные вопросы