我开发了一个由opentok使用的应用程序。他们正在使用RMTP,443端口。我想检查这个端口是在android wifi连接网络中打开的。我怎么能检查一下。任何帮助都将不胜感激
答案 0 :(得分:0)
private static class MyTask extends AsyncTask < Void, Void, Void > {
private Context mContext;
Boolean block = false;
MyTask(Context context) {
if (context == null) {
throw new IllegalArgumentException("Context can't be null");
}
mContext = context;
}@Override
protected Void doInBackground(Void...params) {
Socket socket = null;
try {
InetAddress address = InetAddress.getByName(Constants.SERVER_PORT_CHECK);//give your host address here "www.example.com"
String host = address.getHostAddress();
socket = new Socket(host, 443);
socket.setSoTimeout(5000);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
block = true;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
block = true;
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
if (block) {
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ContactWithOperator.opref);
alertDialogBuilder.setIcon(android.R.drawable.ic_dialog_alert);
alertDialogBuilder.setTitle(R.string.Port_block_title);
alertDialogBuilder.setMessage(R.string.Port_block_msg);
alertDialogBuilder.setNeutralButton("Ok", new DialogInterface.OnClickListener() {@Override
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialogBuilder.show();
//do your action here
}
super.onPostExecute(aVoid);
}
}