由于Android 10+不再允许您以编程方式连接wifi网络(您只能建议/将网络添加到列表中,但如果您有现有的WiFi连接,它们可能永远不会连接),所以我想使用wifi Easy connect (https://source.android.com/devices/tech/connect/wifi-easy-connect),我假设这基本上就是qr代码扫描选项,它是从wifi设置中访问的。
文档指出,您应该检查它是否受支持:
Public APIs are available in Android 10 for use by apps:
WifiManager#isEasyConnectSupported: Queries the framework to determine whether the device supports Wi-Fi Easy Connect.
Activity#startActivityForResult(ACTION_PROCESS_WIFI_EASY_CONNECT_URI): Allows apps to integrate Wi-Fi Easy Connect into their onboarding/setup flow.我所做的是:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
{
val wifiManager = getSystemService(Context.WIFI_SERVICE) as WifiManager
if (wifiManager.isEasyConnectSupported)
{
startActivityForResult(Intent(android.provider.Settings.ACTION_PROCESS_WIFI_EASY_CONNECT_URI), 1237)
}
}但是,由于找不到活动,这会崩溃(我已经在一个像素4XL和模拟器上测试过,它们都运行着R):
E/AndroidRuntime: FATAL EXCEPTION: main
Process: xxx, PID: 8498
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.PROCESS_WIFI_EASY_CONNECT_URI }这有可能被应用程序使用吗?是否有另一种方法可以可靠地连接到无线网络?这是正确的做法吗?还是有一种直接启动设置屏幕的方法?
我在一个android清单中找到了这些,但我找不到启动它们的方法:
<activity
android:name=".wifi.dpp.WifiDppConfiguratorActivity">
<intent-filter>
<action android:name="android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_SCANNER"/>
<action android:name="android.settings.WIFI_DPP_CONFIGURATOR_QR_CODE_GENERATOR"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="android.settings.PROCESS_WIFI_EASY_CONNECT_URI"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="DPP"/>
</intent-filter>
</activity>
<activity
android:name=".wifi.dpp.WifiDppEnrolleeActivity">
<intent-filter>
<action android:name="android.settings.WIFI_DPP_ENROLLEE_QR_CODE_SCANNER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>发布于 2020-10-06 14:12:20
看起来您缺少了DPP URI字符串,应该设置为从文件中。
下面是它应该是什么样子:
// Valid Wi-Fi DPP QR code & it's parameters
private static final String VALID_WIFI_DPP_QR_CODE = "DPP:I:SN=4774LH2b4044;M:010203040506;K:"
+ "MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDIgADURzxmttZoIRIPWGoQMV00XHWCAQIhXruVWOz0NjlkIA=;;";我拿的是这里
您可以查看协议规范内部,以构建您自己的DPP。
希望这能帮你继续调查。我还在这个问题上。所以,请分享任何最新消息。
发布于 2020-10-26 09:03:50
看起来,只有在启动此活动时才支持DPP Uri。发送的这些DPP Uri仅用于引导,而不是用于交换有关WiFi网络身份验证的信息。
为了连接到安卓10上的WiFi网络,谷歌推荐了他们的ConnectivityManager.requestNetwork方法。根据我的经验,这连接到WiFi。然而,它是这样做的,没有互联网连接。请参阅:https://developer.android.com/guide/topics/connectivity/wifi-bootstrap
还有一个WifiNetworkSuggestion,它显示一个通知,并且只建议用户连接到WiFi,这可能是隐藏的,特别是当您的应用程序以沉浸模式运行时。请参阅:https://developer.android.com/guide/topics/connectivity/wifi-suggest
Android11 (API 30)将允许您使用WifiNetworkSuggestions意图添加android.provider.Settings.ACTION_WIFI_ADD_NETWORKS。它类似于旧的WifiManager.addNetwork API。有关详细信息,请参阅:https://developer.android.com/guide/topics/connectivity/wifi-save-network-passpoint-config。
目前,Android 10的最佳选择似乎要么要求用户通过WiFi设置手动连接,要么扫描QR代码,要么输入WiFi分离器。或者使用WifiNetworkSuggestion API。
发布于 2021-02-12 09:54:03
我也在努力运用这一意图,到目前为止还没有任何运气。以下是我的调查结果:
对于有效的URI,您需要使用WPA_CLI命令生成的注册者mac地址和公钥。
dpp_bootstrap_gen type=qrcode mac=<mac-address-of-device> chan=<operating-class/channel> key=<key of the device>键参数是可选的,因为当未提供时,WPA_CLI将为您生成一个
如果您应用了它的mac地址和公钥,则此代码可以到达注册方。
final String VALID_WIFI_DPP_QR_CODE = "" +
"DPP:" +
"I:SN=4774LH2b4044;" +
"M:dea6327ee40a;" + //put here the Enrollee mac address
"K:MDkwEwYHKoZIzj0CAQYIKoZIzj0DAQDDIgADUAQGkdCbThkC1omyOCRX1mCxXZJo8h8yqQ7Jx4WsxFA=;;"; // put here the Enrollee public key
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
if(wifiManager.isEasyConnectSupported())
{
final Intent intent = new Intent(INTENT_PROCESS_WIFI_EASY_CONNECT_URI);
intent.setData(Uri.parse(VALID_WIFI_DPP_QR_CODE));
startActivityForResult(intent, 5000);
}我被困住了,因为Android应用程序没有承认注册者的身份验证响应:
<3>DPP-RX src=96:cc:02:1d:5d:ca freq=2412 type=0
<3>DPP-TX dst=96:cc:02:1d:5d:ca freq=2412 type=1
<3>DPP-TX-STATUS dst=96:cc:02:1d:5d:ca freq=2412 result=no-ACK希望这将触发某人的新想法,以使这一工作。
https://stackoverflow.com/questions/63146969
复制相似问题