9
我有用於獲取來電號碼到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();
telephonyService.answerRingingCall();
}
}
}
能否請你告訴我如何自動接聽來自特定號碼的呼叫?
我試過這段代碼,但似乎沒有工作。我使用三星Galaxy,Android版本2.2。你認爲這是因爲版本? – android 2012-01-05 09:58:06
您是否檢查過Logcat? – Tiago 2012-01-23 21:56:49
不幸的是藍牙解決方案不能在所有情況下工作 - http://stackoverflow.com/a/26195140/1770426 – user1770426 2014-10-04 17:35:12