在android中漫游检测

在android中漫游检测,第1张

概述我正试图检测漫游激活何时发生.到目前为止,我已经使用了以下代码,但由于我无法测试它,我不知道它的正确性TelephonyManagertelephonyManager=TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);PhoneStateListenercellLocationListener=newPhoneStateList

我正试图检测漫游激活何时发生.到目前为止,我已经使用了以下代码,但由于我无法测试它,我不知道它的正确性

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);

我写过这个,认为为了首先激活漫游,信号单元必须改变.请告诉我,我的扣除是否正确,如果不是,我怎么能做到这一点.

解决方法:

我想你想在NetworkInfo类中使用isRoaming().但首先要注册一个更改广播监听器:

<receiver androID:name="YourListener">  <intent-filter>    <action androID:name="androID.net.conn.CONNECTIVITY_CHANGE" />

这将为您提供一个 *** 作名称:ConnectivityManager.CONNECTIVITY_ACTION

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);NetworkInfo ni = cm.getActiveNetworkInfo();//[edit: check for null]if(ni != null) {  //...Here check if this is connected and available...  return ni.isRoaming();}

[编辑:已知问题]
注意:某些版本似乎存在错误,其中getActiveNetworkInfo()在漫游时返回null.见:http://code.google.com/p/android/issues/detail?id=11866

我希望这有帮助!

灵光

总结

以上是内存溢出为你收集整理的在android中漫游检测全部内容,希望文章能够帮你解决在android中漫游检测所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1098781.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存