Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way on Android to intercept incoming calls/SMSes to either block/unblock it?

Tags:

android

Is there a way to intercept incomming calls/SMSes (to block or unblock it) on the basis of mobile numbers which are added to screening list?

like image 540
MAkS Avatar asked Jan 26 '26 21:01

MAkS


2 Answers

----> For your question, I think the following will be helpful.

package android_programmers_guide.PhoneCallReceiver;
import java.lang.reflect.Method;
import com.android.internal.telephony.ITelephony;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;
public class PhoneCallReceiver extends BroadcastReceiver
{
    Context context = null;
    private static final String TAG = "THIRI THE WUT YEE";
    private ITelephony telephonyService;
    @Override
    public void onReceive(Context context, Intent intent) 
    {
        Log.v(TAG, "Receving....");
        TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);  
        try 
        {
            Class c = Class.forName(telephony.getClass().getName());
            Method m = c.getDeclaredMethod("getITelephony");
            m.setAccessible(true);
            telephonyService = (ITelephony) m.invoke(telephony);

            Toast tag = Toast.makeText(context, "Call is not allowed in the meeting!!!", Toast.LENGTH_LONG);
            tag.setDuration(25);
            tag.show();


            telephonyService.silenceRinger();
            telephonyService.endCall();
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
        }

 }


}

-----> Here is interface class

package com.android.internal.telephony;
interface ITelephony 
{
    boolean endCall();
    void answerRingingCall();
    void silenceRinger();
}

----> And the Manifest is as follows

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".PhoneCall2"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>
        <receiver  android:name=".PhoneCallReceiver">
            <intent-filter  android:priority="100" >
                <action android:name="android.intent.action.PHONE_STATE" />
            </intent-filter>
        </receiver>


    </application>
    <uses-sdk android:minSdkVersion="3" />
    <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

</manifest> 

---> Honestly, I've found this code on the internet Cheers!

like image 77
Renegade Avatar answered Jan 29 '26 12:01

Renegade


As far as I know the application for receiving calls cannot be modified. However, see How to block calls in android for some creative suggestions.

There seems to be a walkaround for deleting SMS see How to delete an SMS from the inbox in Android programmatically?.

But it is highly questionable for an application to do this, as the sideeffects could be severe. Make sure your users understand this! The best solution IMHO would be to have a separate build of android which supported these child-safety features (I assume that is what you want to use it for).

like image 43
dparnas Avatar answered Jan 29 '26 13:01

dparnas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!