广播接收器不工作的语音网络
问题描述:
我想在移动网络连接中断或接收接收通知。通过以下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);
http://developer.android.com/reference/android/telephony/TelephonyManager.html#listen(android.telephony.PhoneStateListener, INT)