拦截来电和回复短信
lywdx
posted @ 2012年4月14日 23:12
in HelloAndroid
, 4200 阅读
由于系统API并没有提供Itelephony这个电话管理服务类的接口使用,所以就得通过源码中的Itelephony.aidl来生成电话管理服务接口,这样就能够使用到系统操作电话的功能。
新建包com.android.internal.telephony,在包内新建Itelephony.aidl,内容为
interface ITelephony{ boolean endCall(); void answerRingingCall(); /** * Allow mobile data connections. */ boolean enableDataConnectivity(); /** * Disallow mobile data connections. */ boolean disableDataConnectivity(); /** * Report whether data connectivity is possible. */ boolean isDataConnectivityPossible(); }
程序核心代码:
/* *从私有方法中获取ITelephony **/ private void phoner() { manager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); Class<TelephonyManager> c = TelephonyManager.class; Method getITelephonyMethod = null; try { getITelephonyMethod = c.getDeclaredMethod("getITelephony", (Class[]) null); getITelephonyMethod.setAccessible(true); iTelephony = (ITelephony) getITelephonyMethod.invoke(manager, (Object[]) null); } catch (Exception e) { e.printStackTrace(); } }
/* *监听电话状态,判断是否是来电中 */ public void startService(){ //监听电话状态 PhoneStateListener phoneListener = new PhoneStateListener(){ @Override public void onCallStateChanged(int state,String incoming){ if(state == TelephonyManager.CALL_STATE_RINGING){ //判断电话状态为来电 phoner(); iTelephony.endCall();//拦截 sendSMS(); //发送信息 } } }; telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE); telephonyManager.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE); smsManager = SmsManager.getDefault();//获取系统默认的短信管理器 }
/* *根据来电号码回复内容 **/ public void sendSMS(String incoming) { incomingNumber = incoming; if (numberList.contains(incomingNumber)) { String smsText = editTextVisib.getText().toString();//获取要回复的短信内容 smsManager.sendTextMessage(incomingNumber, null, smsText, null,null); //incomingNumber目标号码,smsText短信内容 } }
2023年1月14日 10:07
There are a few ways to block incoming calls and reply to text messages. One way is to use the Do Not Disturb feature on your phone. This will block all calls and notifications unless you have whitelisted certain contacts. You can also use a third-party app to block calls and texts. Many of these apps allow you to set up auto-responses to texts, so you can let people know CBD hemp oil benefits you're busy without having to type out a response yourself.
2024年1月16日 19:09
Very good written article. It will be supportive to anyone who utilizes it, including me. Keep doing what you are doing – can’r wait to read more posts
2024年2月08日 13:37
Thanks for providing recent updates regarding the concern, I look forward to read more.
2024年2月08日 13:45
whoah this web journal is brilliant i truly like perusing your articles. Keep up the awesome work! You know, numerous individuals are chasing around for this information, you’ll be able offer assistance them enormously.
2024年2月08日 13:55
I havent any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.
2024年2月08日 14:15
This is a truly good site post. Not too many people would actually, the way you just did. I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best, with so much class. If wanted to know more about green smoke reviews, than by all means come in and check our stuff. buy traffic
2024年2月08日 14:23
I havent any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us.
2024年2月08日 14:34
People are really interested in your blog. I can see why, because you did a great job of making it interesting. I really appreciate all you've done.
2024年2月08日 14:43
People are really interested in your blog. I can see why, because you did a great job of making it interesting. I really appreciate all you've done.
2024年2月08日 14:56
There are a couple of intriguing points at some point in this posting but I do not determine if them all center to heart. There is certainly some validity but I will take hold opinion until I take a look at it further. Good write-up , thanks and that we want a lot more! Combined with FeedBurner in addition
2024年2月08日 15:10
Thanks for picking out the time to discuss this, I feel great about it and love studying more on this topic. It is extremely helpful for me. Thanks for such a valuable help again.
2024年2月08日 15:23
Great blog here! I wanted to thank you for this very good read post! I definitely enjoyed every bit of it. I have got you book-marked. Thank you for sharing.
2024年2月08日 15:25
I want to convey my passion for your generosity giving support to men and women that must have help with the concern. Your real dedication to passing the solution up and down had become rather invaluable and have frequently permitted folks much like me to achieve their targets. Your personal valuable guidelines means a great deal to me and far more to my peers.
2024年2月08日 16:01
We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work.
2024年2月08日 16:03
Great blog here! I wanted to thank you for this very good read post! I definitely enjoyed every bit of it. I have got you book-marked. Thank you for sharing.
2024年2月08日 16:12
I admire this article for its well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
2024年2月08日 16:16
You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming.
2024年2月08日 16:18
Great blog here! I wanted to thank you for this very good read post! I definitely enjoyed every bit of it. I have got you book-marked. Thank you for sharing.
2024年2月08日 16:24
This web-site is really a walk-through it really is the details you desired about it and didn’t know who to question. Glimpse here, and you’ll absolutely discover it.
2024年2月08日 16:25
I admire this article for its well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
2024年2月08日 16:28
Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with extra information? It is extremely helpful for me.
2024年2月08日 16:29
Great blog here! I wanted to thank you for this very good read post! I definitely enjoyed every bit of it. I have got you book-marked. Thank you for sharing.
2024年2月08日 16:36
I?d need to test with you here. Which is not something I often do! I enjoy reading a post that may make people think. Also, thanks for allowing me to remark!
2024年2月08日 16:41
I truly admire the captivating photograph you shared in the post! The composition, lighting, and subject are beautifully captured, showcasing your talent as a photographer. Well, By profession I am doing proofreading but I love to do photography as well. Keep up the great work and continue to share your stunning visuals with the world!
2024年2月08日 17:01
Step into Panache Clothing, the epitome of style and elegance. This exquisite clothing store offers a curated collection that embodies sophistication and fashion-forward trends.
2024年2月08日 17:05
I?d need to test with you here. Which is not something I often do! I enjoy reading a post that may make people think. Also, thanks for allowing me to remark!
2024年2月08日 17:12
whoah this web journal is brilliant i truly like perusing your articles. Keep up the awesome work! You know, numerous individuals are chasing around for this information, you’ll be able offer assistance them enormously.
2024年2月08日 17:14
We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work.
2024年2月08日 17:16
Truly, this article is really one of the very best in the history of articles. I am a antique ’Article’ collector and I sometimes read some new articles if I find them interesting. And I found this one pretty fascinating and it should go into my collection. Very good work!
2024年2月08日 17:28
There are a couple of intriguing points at some point in this posting but I do not determine if them all center to heart. There is certainly some validity but I will take hold opinion until I take a look at it further. Good write-up , thanks and that we want a lot more! Combined with FeedBurner in addition
2024年2月08日 17:28
You have done a great job on this article. Very accurate and qualitative. We made it easy to read and understand. You have a real talent for writing. thank you so much
2024年2月08日 17:32
Wow, incredible blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your web site is magnificent, let alone the content!
2024年2月08日 17:39
some genuinely choice content on this internet site , saved to my bookmarks .
2024年2月08日 17:45
Thanks for picking out the time to discuss this, I feel great about it and love studying more on this topic. It is extremely helpful for me. Thanks for such a valuable help again.
2024年2月08日 18:07
I was very happy to seek out this web-site.I wanted to thanks for your time for this wonderful read!! I undoubtedly enjoying every little bit of it and I’ve you bookmarked to take a look at new stuff you weblog post.
2024年2月08日 18:15
Would you mind generally if I quote a handful of your current postings provided that I provide you with credit not to mention article sources returning to your internet-site? My website is in the similar area of interest as your own and my targeted customers would definitely make full use of some of the facts you actually present in this article. Please inform me if this is okay for you. Many thanks!
2024年2月08日 18:27
This web-site is really a walk-through it really is the details you desired about it and didn’t know who to question. Glimpse here, and you’ll absolutely discover it.