Thursday, July 18, 2013

Blocking Incoming call in Android Phone


Step 1:

Create Broadcast receiver class for incoming call


package com.javaorigin.android.sample;

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 = "Phone call";
 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);
   //telephonyService.silenceRinger();
   telephonyService.endCall();
  } catch (Exception e) {
   e.printStackTrace();
  }
  
 }

 
}

Step 2:
Create IDL interface for getting core Telephony service 
package name must be com.android.internal.telephony

FileName : ITelephony.aidl
  package com.android.internal.telephony;

  interface ITelephony {

   
    boolean endCall();

  
    void answerRingingCall();

   
    void silenceRinger();

  }
Step 3:
AndroidManifest.xml configuration

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.javaorigin.android.sample.service" android:versionCode="1"
   android:versionName="1.0">
   <application icon="@drawable/icon" label="@string/app_name">
       <service class=".MyService" name=".MyService">
         <intent-filter>
           <action android:value="com.javaorigin.android.sample.service.MY_SERVICE"
                   android:name=".MyService" />

           </intent-filter>
       </service>
      <activity android:name=".SampleAction"
                 android:label="@string/app_name">
           <intent-filter>
               <action name="android.intent.action.MAIN">
               <category name="android.intent.category.LAUNCHER">
           </intent-filter>
       </activity>

   </application>
   <uses-sdk minsdkversion="8">

</manifest>
 

2 comments:

It was a great information and Its really worth enough reading it. The author did an mind blowing work by describing each and every concept in detail. Thanks for such an informative post. Please keep up your good work.
Marine Colleges in Chennai, Engineering Colleges In Chennai

I absolutely admired every bit of it and i additionally accept you book apparent to analysis out fresh things in your site.
UI Design Companies in Bangalore, Web Application Development Companies in Bangalore

Post a Comment