我正在开发一个应用程序,我需要在 Activity 的 onResume() 中检测来电,我正在使用此代码来检测任何来电。
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
PhoneStateListener callStateListener = new PhoneStateListener() {
public void onCallStateChanged(int state, String incomingNumber)
{
if(state==TelephonyManager.CALL_STATE_RINGING){
// Code
}
}
};
telephonyManager.listen(callStateListener,PhoneStateListener.LISTEN_CALL_STATE);
此外,它在 Oreo 以下的所有设备上都能正常工作,而在 Oreo 设备上却无法正常工作,我不确定我哪里做错了
最佳答案
制作一个广播接收器并在 list 文件中声明它,如果你需要它在应用程序未打开时也能工作,否则在 Activity 中制作一个广播接收器,让你的应用程序监听调用(不是字面上的监听,我想你知道我在说什么)。 当你创建它时,只需在 onCreate 函数中输入 registerReceiver(...fill your intent filters, etc...) 并在 onDestroy() 中输入 unregisterReceiver() 即可完成它在关闭 Activity 之前
关于android - 无法检测到奥利奥的来电,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53498787/