gpt4 book ai didi

android - Android手动开启3G连接,并保持开启

转载 作者:IT王子 更新时间:2023-10-29 00:58:12 25 4
gpt4 key购买 nike

如何在打开WiFi的同时在Android中启动3G数据连接?我试过了

IConnectivityManager.setMobileDataEnabled(enabled); // via reflection

它在模拟器中工作,但在我的真实手机 (Droid 2) 中,它会短暂打开然后再次关闭。

来自 shell (adb shell),ip link提供 3G 连接的详细信息:

15: ppp0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 3 link/ppp

但是,它仅在 WiFi 关闭时可用。当 WiFi 打开并且我尝试手动打开它时,它会提示 ppp0 设备不存在。

bash-3.2# ip link set ppp0 up
ip link set ppp0 up
Cannot find device "ppp0"

当我尝试列出设备时,我什至找不到它

bash-3.2# ls /dev/ppp*
ls /dev/ppp*
/dev/ppp

最佳答案

据我了解,如果不修改 Android 平台源代码(至少版本 2.3 和 4),则不可能同时连接 3g 和 WiFi。主要问题是 frameworks/base/core/res/res/values/config.xml 中定义的硬编码连接优先级:

<!-- This string array should be overridden by the device to present a list of network
attributes. This is used by the connectivity manager to decide which networks can coexist
based on the hardware -->
<!-- An Array of "[Connection name],[ConnectivityManager connection type],
[associated radio-type],[priority] -->
<!-- ^^^^^^^^^^---------- Connection priority -->

<string-array translatable="false" name="networkAttributes">
<item>"wifi,1,1,1"</item>
<item>"mobile,0,0,0"</item>
<item>"mobile_mms,2,0,2"</item>
<item>"mobile_supl,3,0,2"</item>
<item>"mobile_hipri,5,0,3"</item>
</string-array>

此 config.xml 然后由 ConnectivityService 读取它订阅了连接/断开连接事件。在连接处理程序中,它决定应该如何处理其他连接:

private void handleConnect(NetworkInfo info) {

//------------8-<--------------------------

// if this is a default net and other default is running
// kill the one not preferred
if (mNetAttributes[type].isDefault()) {
if (mActiveDefaultNetwork != -1 && mActiveDefaultNetwork != type) {
if ((type != mNetworkPreference &&
mNetAttributes[mActiveDefaultNetwork].mPriority >
// ^^^^^^^^^ --- From config.xml
mNetAttributes[type].mPriority) ||
// ^^^^^^^^^-------- From config.xml
mNetworkPreference == mActiveDefaultNetwork) {
// don't accept this one
if (DBG) Slog.v(TAG, "Not broadcasting CONNECT_ACTION " +
"to torn down network " + info.getTypeName());
teardown(thisNet);
return;
//------------8-<--------------------------

关于android - Android手动开启3G连接,并保持开启,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9510279/

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