gpt4 book ai didi

android - android中的漫游检测

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:54:19 25 4
gpt4 key购买 nike

我正在尝试检测漫游激活何时发生。到目前为止,我使用了以下代码,但是因为我无法测试它,所以我不知道它的正确性

TelephonyManager telephonyManager = TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 

PhoneStateListener cellLocationListener = new PhoneStateListener() {
public void onCellLocationChanged(CellLocation location) {
if(telephonyManager.isNetworkRoaming()
{
Toast.makeText(getApplicationContext(),"in roaming",Toast.LENGTH_LONG).show();
}
}
};

telephonyManager.listen(cellLocationListener, PhoneStateListener.LISTEN_CELL_LOCATION);

我写这篇文章时认为,为了让漫游首先激活,信号单元必须改变。请让我知道我的推论是否正确,如果不正确,我该如何完成。

最佳答案

如果你想知道是否有语音漫游,你也可以在 TelephonyManager 中测试 isNetworkRoaming(),即使接收器是由 android.net.conn.CONNECTIVITY_CHANGE 。我认为这也可以避免 getActiveNetworkInfo() 返回 null 时的错误。

public class RoamingListener extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager telephony =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephony.isNetworkRoaming())
Toast.makeText(context, "Is on TelephonyM Roaming", Toast.LENGTH_LONG).show();
}
}

关于android - android中的漫游检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2373779/

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