проверьте это:
Настройте слушателя:
private static class MyPhoneStateListener extends PhoneStateListener{
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength){ /* Do Stuff */
}
catch(Exception ex)
{
}
}
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
stateString = "Idle";
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
stateString = "Off Hook";
break;
case TelephonyManager.CALL_STATE_RINGING:
stateString = "Ringing " + incomingNumber;
break;
}
}
@Override
public void onCellLocationChanged(CellLocation location) {
try
{
super.onCellLocationChanged(location);
}
catch(Exception ex)
{ }
}
};
тогда вы должны зарегистрировать слушателя:
public static void Init_DataRelatedStuff(Context ForeignContext)
{
foreignContext = ForeignContext;
m_psl = new MyPhoneStateListener();
m_telephonyManager = (TelephonyManager)foreignContext.getSystemService(Context.TELEPHONY_SERVICE);
m_telephonyManager.listen(m_psl, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
m_telephonyManager.listen(m_psl, PhoneStateListener.LISTEN_CELL_LOCATION);
m_telephonyManager.listen(m_psl, PhoneStateListener.LISTEN_CALL_STATE);
}
тогда вы можете получить состояние данных:
public static String getDataState()
{
int nType = m_telephonyManager.getDataState();
String value = "UNKNOWN";
switch(nType)
{
case 0://DATA_DISCONNECTED
value = "DISCONNECTED";
break;
case 1://DATA_CONNECTING
value = "CONNECTING";
break;
case 2://DATA_CONNECTED
value = "CONNECTED";
break;
case 3://DATA_SUSPENDED
value = "SUSPENDED";
break;
default:
value = "UNKNOWN";
break;
}
return value;
}
также вам необходимо разрешение в манифесте:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />