1.检查是否有网络连接
public boolean isNetworkConnected(Context context) {
if (context != null) {
ConnectivityManager mConnectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
if (mNetworkInfo != null) {
return mNetworkInfo.isAvailable();
}
}
return false;
}
2.在activity中通过webview打开链接
布局文件中:
<WebView
android:id="@+id/newswebview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
/>
Java文件中