检测接收何时返回Android

时间:2011-02-19 05:04:20

标签: android

如何检测接收何时返回手机?是否有我可以注册的意图 什么时候收到消息?感谢

1 个答案:

答案 0 :(得分:1)

示例代码:[available here]

 package com.piusvelte.wapdroid;

    import static com.piusvelte.wapdroid.WapdroidService.PHONE_TYPE_CDMA;
    import static android.telephony.NeighboringCellInfo.UNKNOWN_RSSI;
    import android.telephony.CellLocation;
    import android.telephony.PhoneStateListener;
    import android.telephony.SignalStrength;
    import android.telephony.TelephonyManager;

    // PhoneStateListener for api >= 7
    public class PhoneListenerApi7 extends PhoneStateListener {
            private WapdroidService mService;

            public PhoneListenerApi7(WapdroidService service) {
                    mService = service;
            }

            public void onCellLocationChanged(CellLocation location) {
                    // this also calls signalStrengthChanged, since signalStrengthChanged isn't reliable enough by itself
                    mService.getCellInfo(location);
            }

            public void onSignalStrengthChanged(int asu) {
                    // add cdma support, convert signal from gsm
                    if ((mService.mTeleManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) || (mService.mTeleManager.getPhoneType() == PHONE_TYPE_CDMA)) mService.signalStrengthChanged((asu > 0) && (asu != UNKNOWN_RSSI) ? (2 * asu - 113) : asu);
                    else mService.release();
            }

            public void onSignalStrengthsChanged(SignalStrength signalStrength) {
                    if (mService.mTeleManager.getPhoneType() == TelephonyManager.PHONE_TYPE_GSM) {
                            int asu = signalStrength.getGsmSignalStrength();
                            mService.signalStrengthChanged((asu > 0) && (asu != UNKNOWN_RSSI) ? (2 * asu - 113) : asu);
                    }
                    else if (mService.mTeleManager.getPhoneType() == PHONE_TYPE_CDMA) mService.signalStrengthChanged(signalStrength.getCdmaDbm() < signalStrength.getEvdoDbm() ? signalStrength.getCdmaDbm() : signalStrength.getEvdoDbm());
                    else mService.release();
            }
    }