我正在努力建立,PhoneStateListener但我得到了一个PhoneCallListener cannot be resolved to a type.
public class ButtonView extends FrameLayout {
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
}
Run Code Online (Sandbox Code Playgroud)
在另一个例子中,我发现它写得像这样,它正在工作
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
// add PhoneStateListener
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
}
Run Code Online (Sandbox Code Playgroud)
我应该在代码中更改什么才能使其正常工作?