gpt4 book ai didi

android - WiFi 扫描应用程序无法上传..不知道是什么问题

转载 作者:行者123 更新时间:2023-11-29 01:45:09 25 4
gpt4 key购买 nike

我有一个完整的代码可以扫描附近的 WiFi 热点并将它们放在列表中,但我在控制台窗口中收到以下消息:

[2014-02-21 15:21:40 - WIFI] Failed to install WIFI.apk on device 'emulator-5554!
[2014-02-21 15:21:40 - WIFI] (null)
[2014-02-21 15:21:41 - WIFI] Launch canceled!

代码没有错误(如下所示):

主 Activity .java

public class MainActivity extends Activity {
WifiManager mainWifiObj;
WifiScanReceiver wifiReciever;
ListView list;
String wifis[];

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView) findViewById(R.id.listView1);
mainWifiObj = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiReciever = new WifiScanReceiver();
mainWifiObj.startScan();
}

protected void onPause() {
unregisterReceiver(wifiReciever);
super.onPause();
}

protected void onResume() {
registerReceiver(wifiReciever, new IntentFilter(
WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
super.onResume();
}

class WifiScanReceiver extends BroadcastReceiver {
@SuppressLint("UseValueOf")
public void onReceive(Context c, Intent intent) {
List<ScanResult> wifiScanList = mainWifiObj.getScanResults();

// String bssid = wifiInfo.getBSSID();

wifis = new String[wifiScanList.size()];
for (int i = 0; i < wifiScanList.size(); i++) {
wifis[i] = ((wifiScanList.get(i)).toString());
Log.i("Data", "ScanResult");

}
list.setAdapter(new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1, wifis));

}
}
}

WIFI list .xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wifi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.wifi.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.wifi.ListWifiActivity"
android:label="This activity has a list of wifi networks" >
</activity>
</application>
</manifest>

activity_main.xml

<RelativeLayout xmlns: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=".MainActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:drawSelectorOnTop="false"
android:background="@android:color/background_dark"
android:listSelector="@android:color/darker_gray" >
</ListView>
</RelativeLayout>

strings.xml文件也显示如下,因为有一个错误,修改后解决了:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">WIFI</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="title_activity_list_wifi">This activity has a list of wifi networks</string>
</resources>

代码没有错误,但我不能不尝试就检查它的功能。

最佳答案

在运行应用方面:

From this SO answer看来您无法使用模拟器扫描 WiFi 连接。 (感谢@DimitarDimitrov 对此的回答)

Currently, while you can use your computer's Internet connection in the emulator, it's not reliable to use it for simulating Wi-Fi. The WifiManager gets confused when you switch/want to test your connectivity state.

更相关的是:

While you can use your Internet for simulating HTTP connections and downloading data, finer control over Wi-Fi connectivity should better be done with a device.

我建议在设备上试用它并从那里继续。

进一步阅读 From kmansoft.com on WiFi in the emulator

The emulator has no WiFi support. For your own apps, you can fake it by checking if running in the emulator. For other apps, you’re most likely out of luck.


关于模拟器上的安装问题,这里有一些关于此错误的链接:

通常 ADB 超时和 PC 功率不足是安装程序错误的原因。

Fail to install apk on emulator

In eclipse, you can increase the timeout. In Eclipse, Go to WINDOW-->Prefrences-->android-->DDMS>increase the timeout value. In my case it was 5000 & i incresed it to 10000 & it worked for me .

还有:

Close the emulator and launch the APP again. That would fix the issue. You might have kept the emulator open for quite some time without doing any activity.

Time out related

Yon can increase your adb timeout setting in eclipse. Go to Preferences-> Android-> DDMS-> find "ADB connection time out (ms)" and give some more higher value.

Also, try to see if your emulator in connected to the DDMS. Either check from DDMS view or run "ADB devices" in command prompt

你能直接通过 ADB 试试吗 adb install -l -r WIFI.apk

关于android - WiFi 扫描应用程序无法上传..不知道是什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21933579/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com