Android Open Source - Interception Call Helper






From Project

Back to project page Interception.

License

The source code is released under:

# The Code Project Open License (CPOL) 1.02 ###Preamble This License governs Your use of the Work. This License is intended to allow developers to use the Source Code and Executable Files provided a...

If you think the Android project Interception listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.bitgriff.androidcalls;
/*ww w. j ava2  s.c  o  m*/

import com.bitgriff.androidcalls.Block;
import com.sparsa.write2file.write2file;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.RemoteException;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Hashtable;

import telephony.ITelephony;

/**
 * Helper class to detect incoming and outgoing calls.
 * @author Moskvichev Andrey V.
 *
 */
public class CallHelper {

   /*
        Class global variable declaration.
    */
    private Context ctx;
    private Intent intent;
    private TelephonyManager tm;
    private CallStateListener callStateListener;
    private String counCode;
    private String TAG = "CallHelper: ";
    private String areaCode;
    private String cityCode;
    private String asciiCode;
    private String asciiOne;
    private String asciiTwo;
    private String e;

    // Object instances.
    write2file writer = new write2file();
    Block blk = new Block();

    /**
   * Listener to detect incoming calls. 
   */
  private class CallStateListener extends PhoneStateListener {


        Hashtable <String, String> ht = new Hashtable<String, String>();
/*
        String[] keys = { "32", "33", "34", "35", "36", "37", "38","39",
                          "40", "41", "42", "43", "44", "45","46",
                          "47", "48", "49", "50", "51","52", "53",
                          "54", "55", "56", "57","58","59","60", "61",
                          "62", "63", "64", "65", "66", "67", "68", "69",
                          "70", "71", "72", "73", "74", "75","76", "77", "78","79", "80"

                        };

        String[] values = { " ", "A","B","C","D","E","F", "G", "H" ,"I",
                            "J", "K", "L", "M", "N", "O", "P","Q",
                            "R","S","T","U","V","W","X","Y","Z"
                          };

*/
    public void onCallStateChanged(int state, String incomingNumber) {

            /*
               Hash table to match incoming call numbers to interger values.
               http://developer.android.com/reference/java/util/Hashtable.html#get%28java.lang.Object%29
             */

            /*
            for(int i = 0; i < keys.length; i++) {

                ht.put(keys[i], values[i]);
            }
*/
            Log.v(TAG, " incoming number: " + incomingNumber);

      switch (state) {
      case TelephonyManager.CALL_STATE_RINGING:
      // called when someone is ringing to this phone

                try {
                    /*
                            Here is where we lied and said we took the last 7 digits.
                            We must fix this :/
                     */
                    counCode = incomingNumber.substring(0,3);
                    Log.v(TAG, "Area code is:" + counCode);

                    areaCode = incomingNumber.substring(3,6);
                    Log.v(TAG, "First 3 of local code is:" + areaCode);

                    cityCode = incomingNumber.substring(6,10);
                    Log.v(TAG, "Ascii code is:" + cityCode);

                    asciiOne = cityCode.substring(0,2);
                    Log.v(TAG, "Ascii one is:" + asciiOne);

                    asciiTwo = cityCode.substring(2,4);
                    Log.v(TAG, "Ascii two is:" + asciiTwo);

                    try {

                        Log.v(TAG, "Letter 1: " + ht.get(asciiOne ) + " to file");
                        Log.v(TAG, "Letter 2: " + ht.get(asciiTwo) + " to file");
                        String word = ht.get(asciiOne) + ht.get(asciiTwo);
                        writer.writeToFile(word);


                    } catch (Exception e) {
                        Log.v(TAG, "Error: "+ e + "\nThe value most likely does not exist" +
                                   " in the hashtable.");
                    }

                } catch(Exception e) {

                    // Something bad happened when we were spicing the string.
                    Toast.makeText(ctx, "Error, something awful has occurred!: " +
                                   e, Toast.LENGTH_SHORT);
                    Log.v(TAG, "We are in the exception clause due to: " + e);

                }

                break;
      }
    }


    }

  public CallHelper(Context ctx) {
    this.ctx = ctx;

    callStateListener = new CallStateListener();
  }

  /**
   * Start calls detection.
   */
  public void start() {
    tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);
    IntentFilter intentFilter = new IntentFilter(Intent.ACTION_NEW_OUTGOING_CALL);
  }
  
  /**
   * Stop calls detection.
   */
  public void stop() {
    tm.listen(callStateListener, PhoneStateListener.LISTEN_NONE);

  }

  }




Java Source Code List

com.bitgriff.androidcalls.Block.java
com.bitgriff.androidcalls.BuildConfig.java
com.bitgriff.androidcalls.BuildConfig.java
com.bitgriff.androidcalls.CallDetectService.java
com.bitgriff.androidcalls.CallHelper.java
com.bitgriff.androidcalls.MainActivity.java
com.sparsa.write2file.write2file.java