Всякий раз, когда я пытаюсь взять время загрузки из веб-браузера Android, оно дает мне одинаковое количество 1.5701998E12
секунд для любого загружаемого веб-сайта. Я знаю, что мой интернет работает медленно, но я не думаю, что он такой медленный. Я пытался решить проблему, но мне не повезло.
package com.example.new_app;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.util.Date;
public class MainActivity extends AppCompatActivity {
WebView webView;
float end;
final Context context = this;
String UR_L;
String numberAsString;
float start;
float total;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient() {
public void onPageStarted(WebView view, String url) {
start = (new Date()).getTime();
}
//This function will take in the finished load time and create an alert
public void onPageFinished(WebView view, String url) {
end = (new Date()).getTime();
total=end-start;
numberAsString = String.valueOf(total);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
// set title
alertDialogBuilder.setTitle("Your Load Time");
// set dialog message
alertDialogBuilder
.setMessage(numberAsString)
.setCancelable(false)
.setNegativeButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("http://www.Google.com");
}
}