當前位置:首頁 » 密碼管理 » 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-05-15 05:20:00 瀏覽:507
安裝了zlib編譯報錯 發布:2025-05-15 05:19:56 瀏覽:166
二分演算法無序 發布:2025-05-15 05:18:22 瀏覽:28
網易我的世界伺服器組件怎麼安裝 發布:2025-05-15 05:16:58 瀏覽:311
如何復制密碼狗 發布:2025-05-15 05:15:28 瀏覽:737
c語言報告三 發布:2025-05-15 05:10:37 瀏覽:844
09壓縮餅干 發布:2025-05-15 05:05:58 瀏覽:279
迭代法編程c 發布:2025-05-15 04:58:01 瀏覽:815
用什麼dns伺服器地址快 發布:2025-05-15 04:52:59 瀏覽:27
手機端so反編譯 發布:2025-05-15 04:50:55 瀏覽:610