广播接收器不工作的语音网络 [英] Broadcast Receiver not working for voice network

查看:205
本文介绍了广播接收器不工作的语音网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在移动网络连接中断或接收接收通知。通过以下code,我可以收到通知的Wi-Fi(数据)连接,而不是手机(语音)连接。

I want to receive notification when Mobile network connection is lost or received. Through following code, I can receive notification for Wi-Fi (Data) connection but not for Mobile (Voice) connection.

清单:

<uses-permission android:name="android.permission.ACCESS_NETWORK_ST ATE"/>

<application android:icon="@drawable/icon" android:label="@string/app_name">
 <receiver android:name=".notifier">
     <intent-filter>
         <action android:name="android.net.conn.CONNECTIVITY_CHANGE " />
     </intent-filter>
 </receiver>
</application>

Java的:

public class notifier extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast toast = Toast.makeText(context, "Network Changed !!", Toast.LENGTH_LONG);
        toast.show();
    }
}

请告诉我,我怎么能收到通知移动网络(语音)

Please tell me, how can I receive notification for Mobile Network (Voice).

推荐答案

伪code!

PhoneStateListener myListener = new PhoneStateListener() {
    @Override
    public void onServiceStateChanged (ServiceState serviceState) {
        // Handle different service states here.
    }
};

((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE))
    .listen(myListener, PhoneStateListener.LISTEN_SERVICE_STATE);

<一个href=\"http://developer.android.com/reference/android/telephony/TelephonyManager.html#listen%28android.telephony.PhoneStateListener,%20int%29\" rel=\"nofollow\">http://developer.android.com/reference/android/telephony/TelephonyManager.html#listen(android.telephony.PhoneStateListener, INT)

这篇关于广播接收器不工作的语音网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆