1

以下将为我提供基本的 wifi 信息,但我想要硬件信息:

WiFiScanReceiver.java

import java.util.List;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.util.Log;
import android.widget.Toast;

public class WiFiScanReceiver extends BroadcastReceiver {

    private static final String TAG = "WiFiScanReceiver";
    systemInfo systemInfo;

    public WiFiScanReceiver(systemInfo systemInfo) {
        super();
        this.systemInfo = systemInfo;
    }

    @Override
    public void onReceive(Context c, Intent intent) {
        List<ScanResult> results = systemInfo.wifi.getScanResults();
        ScanResult bestSignal = null;
        for (ScanResult result : results) {
            if (bestSignal == null
                    || WifiManager.compareSignalLevel(bestSignal.level,
                            result.level) < 0) bestSignal = result;
        }
        String message = String.format(
                "%s networks found. %s is the strongest.", results.size(),
                bestSignal.SSID);
        Toast.makeText(systemInfo, message, Toast.LENGTH_LONG).show();
        Log.d(TAG, "onReceive() message: " + message);
    }
}

系统信息.java

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.IntentFilter;

import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class systemInfo extends Activity implements OnClickListener {

    private static final String TAG = "WiFiDemo";
    WifiManager wifi;
    BroadcastReceiver receiver;
    TextView textStatus;
    Button buttonScan;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // Setup UI
        textStatus = (TextView) findViewById(R.id.textStatus);
        buttonScan = (Button) findViewById(R.id.buttonScan);
        buttonScan.setOnClickListener(this);
        // Setup WiFi
        wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        // Get WiFi status
        WifiInfo info = wifi.getConnectionInfo();
        textStatus.append("\n\nWiFi Status: " + info.toString());
        // List available networks
        List<WifiConfiguration> configs = wifi.getConfiguredNetworks();
        for (WifiConfiguration config : configs) {
            textStatus.append("\n\n" + config.toString());
        }
        // Register Broadcast Receiver
        if (receiver == null) receiver = new WiFiScanReceiver(this);
        registerReceiver(receiver, new IntentFilter(
                WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
        Log.d(TAG, "onCreate()");
        MemoryInfo mi = new MemoryInfo();
        ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        activityManager.getMemoryInfo(mi);
        long availableMegs = mi.availMem / 1048576L;
        System.out.println("availableMegs:::::::::::" + availableMegs);
    }

    @Override
    public void onStop() {
        unregisterReceiver(receiver);
    }

    public void onClick(View view) {
        Toast.makeText(this, "On Click Clicked. Toast to that!!!",
                Toast.LENGTH_LONG).show();
        if (view.getId() == R.id.buttonScan) {
            Log.d(TAG, "onClick() wifi.startScan()");
            wifi.startScan();
            String ab = getInfo();
            System.out.println("CPU INFORMATON:::::::::::::\n" + ab);
            textStatus.append("CPU INFORMATON:::::::::::::\n" + ab);
        }
    }

    private String getInfo() {
        StringBuffer sb = new StringBuffer();
        sb.append("abi: ").append(Build.CPU_ABI).append("\n");
        if (new File("/proc/cpuinfo").exists()) {
            try {
                BufferedReader br = new BufferedReader(new FileReader(new File(
                        "/proc/cpuinfo")));
                String aLine;
                while ((aLine = br.readLine()) != null) {
                    sb.append(aLine + "\n");
                }
                if (br != null) {
                    br.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }
}

权限是

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

这给了我基本的wifi信息。但我想要硬件信息..

一个重要的区别是 CPU 架构。虽然几乎所有的安卓设备都使用 ARM CPU,但它有不同的版本,包括 armv5、armv5te、armv6、armv6 with VFP、armv7、armv7 with VFP、armv7 with neon 等。

4

1 回答 1

0

如果您的问题是如何获取有关 WiFi 芯片的硬件信息,那么答案很简单:Android 不提供这种数据,除了 MAC 地址(顺便说一句,这不是真正的硬件信息)。

于 2012-08-29T10:26:36.540 回答