我有获取Android手机来电号码的代码.但是当来电来自特定号码时,我想自动接听电话.
我在互联网上找到了这个代码:
public class ServiceReceiver extends BroadcastReceiver {
private static final String TAG = null;
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "GOT SOMETHING", Toast.LENGTH_SHORT).show();
MyPhoneStateListener phoneListener = new MyPhoneStateListener();
TelephonyManager telephony = (TelephonyManager)
context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);
Bundle bundle = intent.getExtras();
String phoneNr = bundle.getString("incoming_number");
Log.v(TAG, "phoneNr: " + phoneNr);
String numb = "+4348873541";
Class c = Class.forName(telephony.getClass().getName());
Method m = c.getDeclaredMethod("getITelephony");
m.setAccessible(true);
if (phoneNr.equals(numb)) {
ITelephony telephonyService = (ITelephony) m.invoke(telephony);
telephonyService = (ITelephony) m.invoke(telephony);
telephonyService.silenceRinger(); …Run Code Online (Sandbox Code Playgroud) 我想接听电话.我找到了意图,android.intent.action.ANSWER但似乎我获得的唯一效果是ActivityNotFoundException.为什么?这是一个弃用的意图吗?我怎样才能达到答案?我也听说过"telnet技术".那是什么?
谢谢
我想让我的应用程序接听电话,这样我就可以在允许用户回答之前做一些处理,也许只是在InCallScreen上显示我的活动,但我无法做到这一点.当我使用intentFilter与<action android:name="android.intent.action.ANSWER"></action>来电时InCallScreen启动而不是我的活动和使用broadcastReciever时<action android:name="android.intent.action.PHONE_STATE"></action>我不能使用abortBroadcast()方法,因为它的无序广播.
请帮忙
编辑1
我设法在onReceive of BroadcastReceiver方法中开始我的活动之前等待1秒钟在InCallScreen上显示我的活动但是InCallScreen首先显示一段时间,这可能允许用户在处理开始之前回答并且如果我减少了等待的时间可能会导致InCallScreen显示在我的活动上方.任何其他解决方案将不胜感激.