2015-12-09 40 views
1

我想創建一個應用程序,阻止所有不在聯繫人中的號碼。 我已閱讀this,但它並不完美。 如何做到這一點?感謝您的閱讀如何以編程方式阻止來自未知號碼的來電?

+1

你試過編碼嗎? – Pankaj

+0

我試試這個:telephonyService =(ITelephony)m.invoke(tm); telephonyService.silenceRinger(); telephonyService.endCall(); –

+0

但我不知道如何阻止未知的號碼 –

回答

0

這是一種使用它的方法。首先,你必須在你的項目中使用ITelephony。我會給你一個例子在下面的鏈接中使用它。其次,你必須插入代碼,當您重新啓動手機按以下方式啓動服務:

在AndroidManifest文件

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 

更改爲:

@Override 
public void onReceive(Context context, Intent intent) { 
    Intent serviceIntent = new Intent(context,BackgroundService.class); 
    startService(serviceIntent); 
    } 

的示例代碼在https://github.com/Levon-Petrosyan/Call_redirect_and_reject