网络
2016-09-23 17:28
295 查看
1.向服务器发送http请求 一 publicbooleansendPhoneInfo(Stringpath){ URLurl=null; try{ url=newURL(path); HttpURLConnectionconn=(HttpURLConnection)url.openConnection(); conn.setConnectTimeout(5000); conn.setRequestMethod("GET"); if(conn.getResponseCode()==200){ returntrue; } }catch(Exceptione){ e.printStackTrace(); } returnfalse; } 二
newThread(){ @Override publicvoidrun(){ App.isSuccess=sendPhoneInfo(path); Log.d("czDebug",path); } }.start(); 2.获取IP地址
publicstaticStringgetLocalIpAddress(){ try { for(Enumeration<NetworkInterface>en=NetworkInterface.getNetworkInterfaces();en.hasMoreElements();) { NetworkInterfaceintf=en.nextElement(); for(Enumeration<InetAddress>enumIpAddr=intf.getInetAddresses();enumIpAddr.hasMoreElements();) { InetAddressinetAddress=enumIpAddr.nextElement(); if(!inetAddress.isLoopbackAddress()&&InetAddressUtils.isIPv4Address(inetAddress.getHostAddress())) { returninetAddress.getHostAddress().toString(); } } } } catch(SocketExceptionex) { Log.e("WifiPreferenceIpAddress",ex.toString()); } returnnull; } *依赖httpclient-4.5.2.jar 3.WebView
源码
publicclassWebViewActivityextendsAppCompatActivity{ @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_web_view); //对象 WebViewwebVeiw=(WebView)findViewById(R.id.webview); Stringurl="http://10.237.32.10"; //设置 webVeiw.setWebViewClient(newWebViewClient(){//本activity中显示 @Override publicbooleanshouldOverrideUrlLoading(WebViewview,Stringurl){ view.loadUrl(url); returntrue; } }); WebSettingssettings=webVeiw.getSettings(); settings.setJavaScriptEnabled(true);//启用js //载入 webVeiw.loadUrl(url); } }
布局文件
<?xmlversion="1.0"encoding="utf-8"?> <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.cz.czapp.MainActivity"> <ListView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/listView"> </ListView> </RelativeLayout>
权限
<uses-permissionandroid:name="android.permission.INTERNET"></uses-permission>
相关文章推荐
- 最近的网络热点
- 标题:如何成为一位网络高手
- 连接数据库时发生"一般性网络错误"的另类解释
- IP层网络数据抓包实现方法收藏
- windows socket 网络编程基本知识(中 下 )
- 现身说法谈网络管理:从疲软的技术到正确的管理方法。
- 本地网络连接不能自动获取IP的解决办法
- ACM HDU 4002 Find the maximum(2011年大连赛区网络赛第二题)
- 为写“QQ“做准备------(1)网络编程
- 网络知识回顾(一)
- 使用openssl加密的网络通讯
- UNIX网络编程——揭开网络编程常见API的面纱【上】
- 黑马程序员---网络编程
- 计算机网络中好的期刊和会议
- 现在公开一个DHT网络爬虫网络爬虫供大家一起交流
- Android网络通信两种方法
- 企业级网络部署实验(一)
- 软考复习专题五---计算机网络
- cmd (网络命令大全)
- ios 替换从网络获取的JSON数据中的Null