Log view async resolving of IP addresses in host names

This commit is contained in:
M66B 2016-01-19 22:17:40 +01:00
parent 868ddf0bef
commit 6ffb7eb861
1 changed files with 21 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -14,6 +15,8 @@ import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
public class LogAdapter extends CursorAdapter {
@ -72,7 +75,7 @@ public class LogAdapter extends CursorAdapter {
TextView tvFlags = (TextView) view.findViewById(R.id.tvFlags);
ImageView ivIcon = (ImageView) view.findViewById(R.id.ivIcon);
TextView tvUid = (TextView) view.findViewById(R.id.tvUid);
TextView tvIP = (TextView) view.findViewById(R.id.tvIP);
final TextView tvIP = (TextView) view.findViewById(R.id.tvIP);
// Set values
tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time));
@ -138,5 +141,22 @@ public class LogAdapter extends CursorAdapter {
// tvUid.setText("18888");
tvIP.setText(whois);
new AsyncTask<String, Object, String>() {
@Override
protected String doInBackground(String... args) {
try {
// This requires internet permission
return InetAddress.getByName(args[0]).getHostName();
} catch (UnknownHostException ignored) {
return null;
}
}
@Override
protected void onPostExecute(String host) {
tvIP.setText(host);
}
}.execute(whois);
}
}