簡體   English   中英

如何在Android手機中禁用傳入和傳出呼叫

[英]How to disable incoming & outgoing calls in android phone

我想在Android手機中禁用傳入和傳出呼叫的功能。我的Android手機應該只允許運行GPRS和其他應用程序。

我的Android機型是三星Ace

請建議我解決這個問題。 提前致謝。

此代碼將阻止您的所有通話(INCOMING AND OUTGOING)

import java.lang.reflect.Method;

import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

import com.CallLogApp.helper.BlockNumberHelper;
import com.CallLogApp.util.UDF;
import com.android.internal.telephony.ITelephony;

public class CustomPhoneStateListener extends PhoneStateListener {

    //private static final String TAG = "PhoneStateChanged";
    Context context;
    public CustomPhoneStateListener(Context context) {
        super();
        this.context = context;
    }

    @Override
    public void onCallStateChanged(int state, String outGoingNumber) {
        super.onCallStateChanged(state, outGoingNumber);

        switch (state) {
            case TelephonyManager.CALL_STATE_IDLE:
                break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
                endCallIfBlocked(outGoingNumber);
                break;
            case TelephonyManager.CALL_STATE_RINGING:
                break;
            default:
                break;
        }

     }

     private void endCallIfBlocked(String outGoingNumber) {
        try {
            // Java reflection to gain access to TelephonyManager's
            // ITelephony getter
            TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            Class<?> c = Class.forName(tm.getClass().getName());
            Method m = c.getDeclaredMethod("getITelephony");
            m.setAccessible(true);
            com.android.internal.telephony.ITelephony telephonyService = (ITelephony) m.invoke(tm);  

            if (new BlockNumberHelper(context).isBlocked(outGoingNumber))
            {
                telephonyService = (ITelephony) m.invoke(tm);
                telephonyService.silenceRinger();
                telephonyService.endCall();
            }


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

這里CALL_STATE_OFFHOOK狀態將在您的呼叫連接和接到來電時每次呼叫

沒有任何方法可以你知道天氣是來電還是來電

但是你可以在兩個場景中結束呼叫

任何你使用谷歌的Android API delevop ..

將位於Android的architcture的Applications層。 但是,管理調用是在Applications Framework層中實現的。 所以:

  • 如果要阻止來自應用程序的呼叫,則無法避免電話呼叫狀態發生,因此一旦電話管理器處理了呼叫,請使用telephonyService.endCall()結束呼叫。

  • 如果你真的需要調用不要到達你的應用層..我認為需要一個自定義的android編譯

  • 但您是否認為某些移動電話提供商提供阻止語音通道的“數據卡”? 這些是3G移動互聯網調制解調器中的卡片

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM