令牌上的语法错误,而不是ConstructorHeaderName&令牌“(”,< expected。)上的语法错误

时间:2013-06-27 20:50:13

标签: java android syntax telephonymanager

我收到两个错误,指出令牌上的语法错误,而ConstructorHeaderName则代替&令牌“(”,< expected

)上的语法错误

就行:

mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);

......有什么建议吗?

public class DataCountService extends Service {
    String text = "USR;1";
    String ERROR = Constants.PREFS_NAME;
    private Timer timer = new Timer();
    private long period;
    private long delay_interval;




    EndCallListener callListener = new EndCallListener();
    TelephonyManager mTM = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
    mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);

    private class EndCallListener extends PhoneStateListener {
        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            if(TelephonyManager.CALL_STATE_RINGING == state) {
              //  Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
            }
            if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
                //wait for phone to go offhook (probably set a boolean flag) so you know your app initiated the call.
              //  Log.i(LOG_TAG, "OFFHOOK");
            }
            if(TelephonyManager.CALL_STATE_IDLE == state) {
                //when this state occurs, and your flag is set, restart your app
              //  Log.i(LOG_TAG, "IDLE");
            }
        }
    }

2 个答案:

答案 0 :(得分:4)

该行

mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);

不包含在任何方法中。你应该将它放在constructor(看起来像你想要的)或常规方法中。

答案 1 :(得分:2)

mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);

应该在一个方法里面,而不是直接在class里面。有关示例实现,请参阅this question