【问题标题】:How to detect android phone 3G On Off events如何检测 android 手机 3G On Off 事件
【发布时间】:2013-08-27 03:30:44
【问题描述】:

我正在编写一个处理 3G 使用情况的 android 应用程序.. 当用户打开 3G 移动数据连接时,我想计算 3G 使用的经过时间,并在经过的时间到达特定时间时通知用户..

问题是我不知道如何检测 3G On Off 事件以便在这些事件发生时运行某些代码。 请帮我举一个详细的例子 我是安卓初学者。

我试过用谷歌搜索它,但对我没有帮助。 我想调用一个这样的函数:

     public void function on3GOnCallback(){
                // i will start counting the time here
     }
     public void function 0n3GOffCallback(){
              // `i will stop counting the time here `
     }

【问题讨论】:

    标签: java android events mobile 3g


    【解决方案1】:

    系统级回调是使用BroadcastReceivers 实现的。更多信息请参考Android BroadcastReceiver Tutorial

    移动数据状态的事件由TelephonyManager 广播。特别是,您似乎对TelephonyManager.DATA_CONNECTEDTelephonyManager.DATA_DISCONNECTED 事件感兴趣。您可以通过查询TelephonyManager的网络类型来区分不同类型的数据网络(2G、EDGE、3G等)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-07
      • 2013-10-25
      • 2013-12-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-27
      • 2020-02-09
      • 1970-01-01
      相关资源
      最近更新 更多