Я пытаюсь открыть URL-адрес в WebView и нажать кнопку, чтобы получить URL-адрес с токеном, но безуспешно.
Я пытался следовать предложениям в:
, но все равно не повезло - веб-представление открывается черным до тех пор, пока не открывается диалоговое окно с предупреждением, но без веб-просмотра.
Мой текущий код (в классе MainActivity. java class): private JSONObject processJSON(String customdata, final String edt1) throws IOException, JSONException {
try {
final WebView theWebPage = new WebView(this);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
theWebPage.getSettings().setJavaScriptEnabled(true);
theWebPage.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
theWebPage.getSettings().setDomStorageEnabled(true);
theWebPage.getSettings().setUseWideViewPort(true);
theWebPage.getSettings().setLoadWithOverviewMode(true);
theWebPage.getSettings().setPluginState(WebSettings.PluginState.ON);
theWebPage.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
//setContentView(theWebPage);
theWebPage.loadDataWithBaseURL(<some_valid_oauth2_url>,"",null,null,null);
final WebChromeClient wbc = new WebChromeClient(){
Intent resultIntent = new Intent();
public void onCloseWindow(WebView w){
LazyUri uri;
try {
OAuth2AccessToken globalToken = grantGlobal.withRedirect(uri = new LazyUri(new Precoded(theWebPage.getUrl()))).accessToken(globalExecutor);
resultIntent.putExtra("code", Uri.parse(theWebPage.getUrl()).getQueryParameter("code"));
MainActivity.this.setResult(Activity.RESULT_OK, resultIntent);
setResult(Activity.RESULT_CANCELED, resultIntent);
} catch (IOException e) {
e.printStackTrace();
} catch (ProtocolError protocolError) {
protocolError.printStackTrace();
} catch (ProtocolException e) {
e.printStackTrace();
}
Log.d(TAG, "Window trying to close.");
}
};
theWebPage.setWebChromeClient(wbc);
alert.setView(theWebPage);
alert.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
alert.setTitle("Authroization");
alert.show();
}
}
Использование эмулятора Pixel 2 (JDK 1.7, minSDK 24) в Android Studio 3.5.3. Смотрите скриншот текущего результата: ![Alert window without embeded webview](https://i.stack.imgur.com/NpTUi.png)