相关疑难解决方法(0)

检测Android设备是否具有Internet连接

我需要告诉我的设备是否有Internet连接.我找到了许多答案,如:

private boolean isNetworkAvailable() {
    ConnectivityManager connectivityManager 
         = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    return activeNetworkInfo != null;
}
Run Code Online (Sandbox Code Playgroud)

(摘自检测Android上是否有可用的Internet连接.)

但这是不对的,例如,如果我连接到无法访问Internet的无线网络,此方法将返回true ... 是否有方法可以判断设备是否具有Internet连接,而不是仅仅连接什么?

android internet-connection android-internet

133
推荐指数
6
解决办法
10万
查看次数

如何从Java Android中ping外部IP

我正在为Android 2.2开发一个Ping应用程序.

我尝试我的代码,它的工作原理,但只在本地IP,这是我的问题,我想ping外部服务器.

这是我的代码:

  private OnClickListener milistener = new OnClickListener() {
    public void onClick(View v) {
        TextView info = (TextView) findViewById(R.id.info);
        EditText edit = (EditText) findViewById(R.id.edit);
        Editable host = edit.getText();
        InetAddress in;
        in = null;
        // Definimos la ip de la cual haremos el ping
        try {
            in = InetAddress.getByName(host.toString());
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        // Definimos un tiempo en el cual ha de responder
        try {
            if (in.isReachable(5000)) {
                info.setText("Responde OK");
            } …
Run Code Online (Sandbox Code Playgroud)

java android

53
推荐指数
5
解决办法
12万
查看次数

在Android中Ping应用程序

我正在创建一个应用程序,它将实现"ping"命令的一些功能.问题是,我不知道在ANDROID中使用哪些库/库.有人有任何想法吗?

我访问了这些stackoverflow链接,但他们没有太大的帮助.

android ping

11
推荐指数
2
解决办法
2万
查看次数