当前位置:首页 » 密码管理 » android40访问网络

android40访问网络

发布时间: 2022-05-07 21:25:52

Ⅰ Android4.0系统的手机连接WIFI无线网络的时候连接不上是怎么回事,就是手机上面一直显示正在获取IP地址,

你在WLAN设置中把你的wifi名长摁,然后选择不保存。关闭wifi后再打开,再次输入密码连接上就好了。如果不行再试一次。一般都会有可能出现ip分配冲突的可能性,苹果也是这样,选择忘记之前保存的,然后重新连接。

Ⅱ Android系统,如何设置某个应用程序不允许访问网络

设置方法;以华为手机设置禁止使用手机网络操作为例:


1、首先如图所示,首先点击手机桌面中的设置。


Ⅲ Android如何获取网络连接状态及怎样调用网络配置界面

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetManager {
Context context;

public NetManager(Context context) {
this.context = context;
}

// 判断网络是否可用的方法
public boolean isOpenNetwork() {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
return false;
}

// 判断WIFI网络是否可用的方法
public boolean isOpenWifi() {
ConnectivityManager connManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mWifi = connManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
return mWifi.isConnected();
}
}

public static void netManager(final Context a) {
netManager = new NetManager(a);

if (!netManager.isOpenNetwork()) {
// 如果网络不可用,则弹出对话框,对网络进行设置
Builder builder = new Builder(a);
builder.setTitle("没有可用的网络");
builder.setMessage("是否对网络进行设置?");
builder.setPositiveButton("确定",
new android.content.DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = null;
try {

String sdkVersion = android.os.Build.VERSION.SDK;
if (Integer.valueOf(sdkVersion) > 10) {
intent = new Intent(
android.provider.Settings.ACTION_WIRELESS_SETTINGS);
} else {
intent = new Intent();
ComponentName comp = new ComponentName(
"com.android.settings",
"com.android.settings.WirelessSettings");
intent.setComponent(comp);
intent.setAction("android.intent.action.VIEW");
}
a.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
}
});
builder.setNegativeButton("取消",
null);
builder.show();
}else {
Toast.makeText(a, "网络不给力,请确认您的网络连接", Toast.LENGTH_LONG).show();
}
}
转载,仅供参考。

Ⅳ Android访问网络数据的几种方式Demo

Android应用经常会和服务器端交互,这就需要手机客户端发送网络请求,下面介绍四种常用网络请求方式,我这边是通过Android单元测试来完成这四种方法的,还不清楚Android的单元测试的同学们请看Android开发技巧总结中的Android单元测试的步骤一文。
java.net包中的HttpURLConnection类
Get方式:
[java] view plainprint?
// Get方式请求
public static void requestByGet() throws Exception {
String path = "https://reg.163.com/logins.jsp?id=helloworld&pwd=android";
// 新建一个URL对象
URL url = new URL(path);
// 打开一个HttpURLConnection连接
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
// 设置连接超时时间
urlConn.setConnectTimeout(5 * 1000);
// 开始连接
urlConn.connect();
// 判断请求是否成功
if (urlConn.getResponseCode() == HTTP_200) {
// 获取返回的数据
byte[] data = readStream(urlConn.getInputStream());
Log.i(TAG_GET, "Get方式请求成功,返回数据如下:");
Log.i(TAG_GET, new String(data, "UTF-8"));
} else {
Log.i(TAG_GET, "Get方式请求失败");
}
// 关闭连接
urlConn.disconnect();
}
// Get方式请求
public static void requestByGet() throws Exception {
String path = "https://reg.163.com/logins.jsp?id=helloworld&pwd=android";
// 新建一个URL对象
URL url = new URL(path);
// 打开一个HttpURLConnection连接
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
// 设置连接超时时间
urlConn.setConnectTimeout(5 * 1000);
// 开始连接
urlConn.connect();
// 判断请求是否成功
if (urlConn.getResponseCode() == HTTP_200) {
// 获取返回的数据
byte[] data = readStream(urlConn.getInputStream());
Log.i(TAG_GET, "Get方式请求成功,返回数据如下:");
Log.i(TAG_GET, new String(data, "UTF-8"));
} else {
Log.i(TAG_GET, "Get方式请求失败");
}
// 关闭连接
urlConn.disconnect();
}

Post方式:
[java] view plainprint?
// Post方式请求
public static void requestByPost() throws Throwable {
String path = "https://reg.163.com/logins.jsp";
// 请求的参数转换为byte数组
String params = "id=" + URLEncoder.encode("helloworld", "UTF-8")
+ "&pwd=" + URLEncoder.encode("android", "UTF-8");
byte[] postData = params.getBytes();
// 新建一个URL对象
URL url = new URL(path);
// 打开一个HttpURLConnection连接
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
// 设置连接超时时间
urlConn.setConnectTimeout(5 * 1000);
// Post请求必须设置允许输出
urlConn.setDoOutput(true);
// Post请求不能使用缓存
urlConn.setUseCaches(false);
// 设置为Post请求
urlConn.setRequestMethod("POST");
urlConn.setInstanceFollowRedirects(true);
// 配置请求Content-Type
urlConn.setRequestProperty("Content-Type",
"application/x-www-form-urlencode");
// 开始连接
urlConn.connect();
// 发送请求参数
DataOutputStream dos = new DataOutputStream(urlConn.getOutputStream());
dos.write(postData);
dos.flush();
dos.close();
// 判断请求是否成功
if (urlConn.getResponseCode() == HTTP_200) {
// 获取返回的数据
byte[] data = readStream(urlConn.getInputStream());
Log.i(TAG_POST, "Post请求方式成功,返回数据如下:");
Log.i(TAG_POST, new String(data, "UTF-8"));
} else {
Log.i(TAG_POST, "Post方式请求失败");
}
}
// Post方式请求
public static void requestByPost() throws Throwable {
String path = "https://reg.163.com/logins.jsp";
// 请求的参数转换为byte数组
String params = "id=" + URLEncoder.encode("helloworld", "UTF-8")
+ "&pwd=" + URLEncoder.encode("android", "UTF-8");
byte[] postData = params.getBytes();
// 新建一个URL对象
URL url = new URL(path);
// 打开一个HttpURLConnection连接
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
// 设置连接超时时间
urlConn.setConnectTimeout(5 * 1000);
// Post请求必须设置允许输出
urlConn.setDoOutput(true);
// Post请求不能使用缓存
urlConn.setUseCaches(false);
// 设置为Post请求
urlConn.setRequestMethod("POST");
urlConn.setInstanceFollowRedirects(true);
// 配置请求Content-Type
urlConn.setRequestProperty("Content-Type",
"application/x-www-form-urlencode");
// 开始连接
urlConn.connect();
// 发送请求参数
DataOutputStream dos = new DataOutputStream(urlConn.getOutputStream());
dos.write(postData);
dos.flush();
dos.close();
// 判断请求是否成功
if (urlConn.getResponseCode() == HTTP_200) {
// 获取返回的数据
byte[] data = readStream(urlConn.getInputStream());
Log.i(TAG_POST, "Post请求方式成功,返回数据如下:");
Log.i(TAG_POST, new String(data, "UTF-8"));
} else {
Log.i(TAG_POST, "Post方式请求失败");
}
}

org.apache.http包中的HttpGet和HttpPost类

Get方式:

[java] view plainprint?
// HttpGet方式请求
public static void requestByHttpGet() throws Exception {
String path = "https://reg.163.com/logins.jsp?id=helloworld&pwd=android";
// 新建HttpGet对象
HttpGet httpGet = new HttpGet(path);
// 获取HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
// 获取HttpResponse实例
HttpResponse httpResp = httpClient.execute(httpGet);
// 判断是够请求成功
if (httpResp.getStatusLine().getStatusCode() == HTTP_200) {
// 获取返回的数据
String result = EntityUtils.toString(httpResp.getEntity(), "UTF-8");
Log.i(TAG_HTTPGET, "HttpGet方式请求成功,返回数据如下:");
Log.i(TAG_HTTPGET, result);
} else {
Log.i(TAG_HTTPGET, "HttpGet方式请求失败");
}
}
// HttpGet方式请求
public static void requestByHttpGet() throws Exception {
String path = "https://reg.163.com/logins.jsp?id=helloworld&pwd=android";
// 新建HttpGet对象
HttpGet httpGet = new HttpGet(path);
// 获取HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
// 获取HttpResponse实例
HttpResponse httpResp = httpClient.execute(httpGet);
// 判断是够请求成功
if (httpResp.getStatusLine().getStatusCode() == HTTP_200) {
// 获取返回的数据
String result = EntityUtils.toString(httpResp.getEntity(), "UTF-8");
Log.i(TAG_HTTPGET, "HttpGet方式请求成功,返回数据如下:");
Log.i(TAG_HTTPGET, result);
} else {
Log.i(TAG_HTTPGET, "HttpGet方式请求失败");
}
}

Post方式:
[java] view plainprint?
// HttpPost方式请求
public static void requestByHttpPost() throws Exception {
String path = "https://reg.163.com/logins.jsp";
// 新建HttpPost对象
HttpPost httpPost = new HttpPost(path);
// Post参数
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("id", "helloworld"));
params.add(new BasicNameValuePair("pwd", "android"));
// 设置字符集
HttpEntity entity = new UrlEncodedFormEntity(params, HTTP.UTF_8);
// 设置参数实体
httpPost.setEntity(entity);
// 获取HttpClient对象
HttpClient httpClient = new DefaultHttpClient();
// 获取HttpResponse实例
HttpResponse httpResp = httpClient.execute(httpPost);
// 判断是够请求成功
if (httpResp.getStatusLine().getStatusCode() == HTTP_200) {
// 获取返回的数据
String result = EntityUtils.toString(httpResp.getEntity(), "UTF-8");
Log.i(TAG_HTTPGET, "HttpPost方式请求成功,返回数据如下:");
Log.i(TAG_HTTPGET, result);
} else {
Log.i(TAG_HTTPGET, "HttpPost方式请求失败");
}
}

Ⅳ android如何访问本地网络

如果你是打算用手机测试移动版网页的话(同局域网手机访问pc上的html)。
那可以将局域网内的设备都设置成静态ip。然后使用iis或php环境将网页放到站点目录下。
然后就可以通过ip进行访问了。
如果你打算用手机访问手机上的html页面
那你可以安装一个AndroPHP 然后将html页面放到站点目录下。然后使用给定的ip访问即可

Ⅵ 安卓4.0怎么通过USB共享电脑网络

安卓4.0通过USB共享电脑网络的方法:
1.用USB线将手机和电脑连接。
2.手机开启USB调试。注意:关闭豌豆荚、91手机助手等占ADB的软件。
3.下载ReverseTethering并在电脑上解压。把Tracetool service.apk这个软件安装到手机上,然后在上电脑安装AndroidTool.exe。
4.点击【更新列表】按钮,会发现安卓设备的ID。再点击【Connect】,稍等一会后就能成功连接。这样就通过电脑让手机上网了。
如果是笔记本或者有无线网卡的台式机,只需要在电脑上安装免费WIFI软件,设置好SSID和密码后,手机搜索WIFI,输入密码就能连上了。

热点内容
随机启动脚本 发布:2025-07-05 16:10:30 浏览:535
微博数据库设计 发布:2025-07-05 15:30:55 浏览:31
linux485 发布:2025-07-05 14:38:28 浏览:310
php用的软件 发布:2025-07-05 14:06:22 浏览:760
没有权限访问计算机 发布:2025-07-05 13:29:11 浏览:436
javaweb开发教程视频教程 发布:2025-07-05 13:24:41 浏览:727
康师傅控流脚本破解 发布:2025-07-05 13:17:27 浏览:246
java的开发流程 发布:2025-07-05 12:45:11 浏览:696
怎么看内存卡配置 发布:2025-07-05 12:29:19 浏览:288
访问学者英文个人简历 发布:2025-07-05 12:29:17 浏览:837