2012-11-10 44 views
2

我想創建一個應用程序,一旦應用程序啓動,它將顯示兩個按鈕(開始和停止按鈕),一旦用戶單擊開始按鈕,呼叫功能將被阻止一段時間,直到用戶再次啓動應用程序並單擊停止按鈕停止此功能。任何幫助,請其緊迫阻止從我的Android應用程序出去的電話。

總之我會告訴我要使用此活動僅

請有沒有辦法這樣做,以阻止我的電話呼出???

+0

更好地檢查這些鏈接 [Link1](http://stackoverflow.com/questions/7595092/how-to-block-outgoing-calls-and-text-sms) [Link2](http:// stackoverflow。/7121508/android-taking-complete-control-of-phone-is-it-how-712/7121586) [Link3](http://code.google.com/p/krvarma-android -samples/source/browse/trunk/DetectCalls/src/com/varma/samples/detectcalls/receivers/OutgoingCallReceiver.java) – andy

回答

6

您可以使用Broaadcast接收器的onReceive方法中的setResultData(null)函數阻止傳出呼叫。

public class BlockOutgoing extends BroadcastReceiver 
{ 
    String number; 
    @Override 
    public void onReceive(Context context, Intent intent) 
    { 
     Log.d("12280", "asdasNumber is-->> " + number); 
     number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER); 
     setResultData(null); 
     Toast.makeText(context, "Outgoing Call Blocked" , 5000).show(); 

    } 
} 

在manifest文件中,你需要註冊接收這樣,

<receiver 
      android:name=".BlockOutgoing" 
      android:label="@string/app_name" > 
      <intent-filter android:priority="1"> 

<action android:name="android.intent.action.NEW_OUTGOING_CALL" /> 

      </intent-filter> 
     </receiver> 

還要定義攔截呼出權限,

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

編輯 - 要取消註冊廣播接收器,請按照此link

+0

thanx it works ,,抱歉,但你能告訴我如何處理這個廣播 – surya

+0

我編輯了我的回答以反映您需要的更改。 –

+0

你好我試過這個但它對我沒有任何作用,所以還有其他方法可以讓我解釋你的問題......這裏我有兩個按鈕,當我點擊第一個按鈕時,它應該開始播放並停止播放去電話,當我再次運行我的應用程序,如果我點擊第二個按鈕然後廣播接收機應該開始或停止我猜,我的電話應該開始再次 – surya

0

阻止傳出呼叫請看這 Link,這是阻止傳出呼叫的工作示例。

相關問題