In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to implement Android automatic block and answer function APK black and white list content. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.
The relationship between automatic answer and hang up is as follows
1. 首先在启动apk初始界面的activity中,启动service服务,开始监听通话状态(InCallService)
//启动通话状态监听服务 private void startCallListen() { Intent intent = new Intent(CallAndMessageEntranceActivity.this, InCallService.class); startService(intent);}
2. 在通话监听服务中,监听通话状态,当通话状态为CALL_STATE_RINGING时处理通话。
public class InCallService extends Service { private TelecomManager mTelecomManager; private TelephonyManager mTelephonymanager; MyPhoneStateListener mMyPhoneStateListener = new MyPhoneStateListener(); @Override public void onCreate() { Log.e("InCallService", "onCreate()"); super.onCreate(); //获取电话服务 mTelecomManager = (TelecomManager) getSystemService(Context.TELECOM_SERVICE); mTelephonymanager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); } @Override public int onStartCommand(Intent intent, int flags, int startId) { if (mTelephonymanager == null) { mTelephonymanager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); } mTelephonymanager.listen(mMyPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); return super.onStartCommand(intent, flags, startId); } //监听通过话 public class MyPhoneStateListener extends PhoneStateListener { @RequiresApi(api = Build.VERSION_CODES.P) @Override public void onCallStateChanged(int state, final String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_IDLE: //通话空闲状态 break; case TelephonyManager.CALL_STATE_RINGING: //通话来电状态 try { Log.e("C_M_BlackCallService", "Monitor incoming calls"); //拦截来电判断来电时黑名单or白名单 splitWhiteAndBlack(incomingNumber); } catch (Exception e) { e.printStackTrace(); } break; case TelephonyManager.CALL_STATE_OFFHOOK: //电话挂起状态 break; } } } //incomingNumber:来电号码 依据来电号码判断黑白名单 private void splitWhiteAndBlack(String incomingNumber) { //1.黑名单自动挂断 mTelecomManager.endCall(); //2.白名单自动接听 mTelecomManager.acceptRingingCall(); } @Override public void onDestroy() { super.onDestroy(); }感谢各位的阅读!关于"如何实现Android自动拦截与接听功能APK黑白名单"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.