0
我試圖在服務實現手機狀態監聽器和我得到的錯誤:語法錯誤「擴展」拋出預期 - 在服務實施PhoneStateListener時
Syntax error on token "extends", throws expected
但是當我改變extends
到throws
我得到3級新的錯誤,指出:
EndCallListener cannot be resolved to a type
EndCallListener cannot be resolved to a type
No exception of type PhoneStateListener can be thrown; an exception type must be a subclass of Throwable
有什麼建議?
阿曼尼斯旺
public void onCreate() extends PhoneStateListener {
EndCallListener callListener = new EndCallListener();
TelephonyManager mTM = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
}
public void onCallStateChanged(int state, String incomingNumber) {
if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
// set number of calls to 1 in SharedPreferences
SharedPreferences pref = getApplicationContext()
.getSharedPreferences("DataCountService", 0);
Editor editor = pref.edit();
editor.putString("calls", "1");
editor.commit();
}