In this post, you can learn on how to block an incoming call through android programming examples. There are few android applications in the market what you can make use of it to block the unwanted incoming calls. You can learn on the functionality behind. After getting good ideas on this you can really start building your own app. Let us see the example below.
Receiver.java
package com.udhaya;
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;
public class PhoneCallReceiver extends BroadcastReceiver {
Context context = null;
private static final String TAG = "Call";
private ITelephony telephonyService;
@Override
public void onReceive(Context context, Intent intent) {
Log.v(TAG, "Receving SMS....");
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);
//telephonyService.silenceRinger();
telephonyService.endCall();
} catch (Exception e) {
e.printStackTrace();
}
}}
2. Create an IDL interface in java for getting a core Telephony Service. Create a package named as com.android.internal.telephony
ITelephony.aidl
package com.android.internal.telephony;
interface ITelephony {
boolean endCall();
void answerRingingCall();
void silenceRinger();
}
3. Now configure the android manifest file and add the Uses permissions in it as illustrated below.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.udhaya"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<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="5" />
<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" />
<uses-sdk android:minSdkVersion="8" />
</manifest>
Not working!!!
ReplyDeleteNot working!!!
ReplyDelete