2010-04-09 36 views
7

我想接聽電話。我找到了意圖android.intent.action.ANSWER,但似乎我得到的唯一影響是一個ActivityNotFoundException。爲什麼?這是一個不贊成的意圖嗎?我如何獲得答案?我也聽說過「telnet技術」。那是什麼?如何以編程方式接聽電話?

感謝

回答

4

這是不可能,檢查this線程以獲取更多信息。

+0

好的,看到線程......但爲什麼有這種意圖?它甚至不被棄用! – Matroska 2010-04-09 20:58:08

+0

我知道,如果你是谷歌的ACTION_ANSWER,你會發現很多關於人們爲了找到一種自動打電話的方式而瘋狂的話題。這個功能肯定已被Android員工關閉(安全原因?)。 – systempuntoout 2010-04-10 10:58:46

2

這個事件是不行的。 你應該使用:

Intent i = new Intent(Intent.ACTION_MEDIA_BUTTON); 
KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_HEADSETHOOK); 
i.putExtra(Intent.EXTRA_KEY_EVENT, event); 
context.sendOrderedBroadcast(i, null); 

是模擬按鍵的bhavior。

+0

它實際上工作嗎?我還沒有嘗試過。你是否?謝謝 – Matroska 2010-06-03 11:43:27

+1

它的工作原理,但揚聲器電話是靜音的。任何想法如何防止這一點。我在AudioManager類中嘗試setMicrophoneMute(false),但沒有結果? – Bear 2011-06-22 14:05:42

+0

並不總是在棒棒糖中工作。嘗試從服務中使用它,並且當從屏幕關閉狀態(當電話空閒時進行呼叫)時不起作用。 – leRobot 2015-04-07 14:40:26

3

可以接聽來電電話。看看這個:here

+1

這實際上是使用黑客技術,它可能會或可能不會在Android的下一次更新中發揮作用。 – 2013-06-25 20:28:02

0

應答意圖應發送到InCallScreen。

adb shell am start -n com.android.phone/.InCallScreen -a android.intent.action.ANSWER 
6

你也可以將通話的KeyEvent來接聽電話 但設備需要植根

接聽電話:

try { 
    Thread.sleep(800); 
    Process process = Runtime.getRuntime().exec(new String[]{ "su","-c","input keyevent 5"}); 
    process.waitFor(); 

}catch (Exception e) { 
    e.printStackTrace(); 
} 

掛斷電話:

try { 
    Thread.sleep(800); 
    Process process = Runtime.getRuntime().exec(new String[]{ "su","-c","input keyevent 6"}); 
    process.waitFor(); 

}catch (Exception e) { 
    e.printStackTrace(); 
} 
+0

一個非常簡單和簡單的解決方案。爲我工作。多謝了! – Basher51 2014-10-23 05:06:46

+0

這對於Android N來說已經不再可能了。https://source.android.com/security/bulletin/2016-03-01.html – AnixPasBesoin 2017-01-31 04:20:44

+0

看看日期。這是5年前:-) – Seifolahi 2017-01-31 06:15:09

1

的方法用於模擬BT手機不適用於所有Android版本和a由於BT手機處理可能會有所不同。

在很多設備和Android版本,包括在模擬的撥號器的壓力和呼叫按鈕的釋放證明,最好的方法:

Intent buttonDown = new Intent(Intent.ACTION_MEDIA_BUTTON); 
buttonDown.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, 
KeyEvent.KEYCODE_CALL)); 
context.sendOrderedBroadcast(buttonDown, "android.permission.CALL_PRIVILEGED"); 

// froyo and beyond trigger on buttonUp instead of buttonDown 
Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON); 
buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, 
KeyEvent.KEYCODE_CALL)); 
context.sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED"); 

你可以做到這一點還通過發送Shell命令「輸入KeyEvent的5 「通過adb或通過Runtime.exec,但在我的情況下,並不適用於所有設備

2

這從Android 2.2到4.0,現在將try catch添加到最後一行後它爲4.1.2和4.2工作說話不知道它是如何工作的,但它適用於我。

Log.d(tag, "InSecond Method Ans Call"); 
    // froyo and beyond trigger on buttonUp instead of buttonDown 
    Intent buttonUp = new Intent(Intent.ACTION_MEDIA_BUTTON); 
    buttonUp.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(
      KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK)); 
    sendOrderedBroadcast(buttonUp, "android.permission.CALL_PRIVILEGED"); 

    Intent headSetUnPluggedintent = new Intent(Intent.ACTION_HEADSET_PLUG); 
    headSetUnPluggedintent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); 
    headSetUnPluggedintent.putExtra("state", 0); 
    headSetUnPluggedintent.putExtra("name", "Headset"); 
    try { 
     sendOrderedBroadcast(headSetUnPluggedintent, null); 
    } catch (Exception e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

這是Android 4.1.2爲我工作,以及我對4.2 測試這仍然給它處理的異常。

0
try { 
Runtime.getRuntime().exec("input keyevent"+Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK)); 
} catch (IOException e) { 
    //handle error here 
} 
相關問題