我正在尝试在服务中实现电话状态侦听器,但出现错误:
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();
}