Android-getHostName()返回应用程序名称?
在我正在开发的android应用程序中,我只是尝试获取与ip地址对应的主机名Android-getHostName()返回应用程序名称?,android,dns,lookup,inetaddress,Android,Dns,Lookup,Inetaddress,在我正在开发的android应用程序中,我只是尝试获取与ip地址对应的主机名 private class hostLookUp extends AsyncTask<InetAddress, Integer, String>{ protected String doInBackground (InetAddress...ip){ int count = ip.length; for (int i = 0; i < count; i++){
private class hostLookUp extends AsyncTask<InetAddress, Integer, String>{
protected String doInBackground (InetAddress...ip){
int count = ip.length;
for (int i = 0; i < count; i++){
String hostName = ip[i].getHostName();
if (isCancelled()) return "ERROR";
else return hostName;
}
return null;
}
}
使用AsyncTask实现它的唯一原因是android不允许我在主线程中调用该函数。
前面的代码用于包含以下代码的子例程
for (int i = 0; i < connectionCount; i++){
statusList[i][0] = addressList[i].toString() + "(" + new hostLookUp().execute(addressList[i]) + ")";;
temp = connectionStatus (statusList[i][1]);
statusList[i][1] = temp;
}
其中0.0.0.0代表出现的任何IP地址,42244450只是一个不断变化的数字。我只想显示正确的主机名,为什么会显示应用程序名
for (int i = 0; i < connectionCount; i++){
statusList[i][0] = addressList[i].toString() + "(" + new hostLookUp().execute(addressList[i]) + ")";;
temp = connectionStatus (statusList[i][1]);
statusList[i][1] = temp;
}
"/0.0.0.0(com.example.Test.MainActivity$hostLookUp@42244450)"