Call blocking/forwarding.

Tutorials with advanced 'difficulty' and more Lines of Code.

Call blocking/forwarding.

Postby Dmitry Zhadan » Thu May 06, 2010 2:18 pm

I'm not a new to Android coding, but I completely locks on following problem.
Is there a way to block (hang up) incoming call, or forward incoming call to another phone number? Using only Android SDK API classes?
Or I need to use Android NDK and some low-level system modules?
I'm can't find in SDK docs any classes for managing incoming phone calls (only for monitoring via android.telephony). But I'm seen on market at least this app:
http://www.chazclout.co.uk/?p=348#more-348
Any suggestions?
SY, Dmitry.
Dmitry Zhadan
Once Poster
Once Poster
 
Posts: 1
Joined: Thu May 06, 2010 2:12 pm
Location: Nikolaev, Ukraine

Top

Re: Call blocking/forwarding.

Postby kaasnake » Fri Jul 09, 2010 9:30 am

i think it uses phoneutils from androil libs. Ive found a piece of source, may be it will be useful for u.
Code: Select all
   <!-- Elite Old:  package="boteros.CallBlocker"-->
   <!-- Elite:  package="blacknWhite.CallBlocker.Pro" -->
   <!-- Pro:  package="blacknWhite.CallBlocker.ProIn" -->
   <!-- Lite:  package="blacknWhite.CallBlocker.Lite" -->


Manifest.xml
- Rename Package:
   Lite: blacknWhite.CallBlocker.Lite
   Pro: boteros.CallBlocker
- Rename folder in src
- Rename app_name in strings.xml
- Ensure openAppInAndroidMarket in Utils.java has boteros.CallBlocker

         // if (action
         // .compareToIgnoreCase("android.intent.action.BOOT_COMPLETED") ==
         // 0) {
         // if (!Data.Settings.preferences.getBoolean("autoStart", true))
         // return;
         // } else


// private static Object phoneObject;

// @SuppressWarnings("unchecked")
// private static Object getPhoneObject() {
// try {
// String telephonyName = "com.android.internal.telephony.ITelephony";
// Class myTelephonyClass = Class.forName(telephonyName);
//
// Class telephonyStubClass = myTelephonyClass.getClasses()[0];
// Method serviceMethod = telephonyStubClass.getMethod("asInterface",
// IBinder.class);
//
// String serviceManagerName = "android.os.ServiceManager";
// Class serviceManagerClass = Class.forName(serviceManagerName);
// Method getServiceMethod = serviceManagerClass.getMethod(
// "getService", String.class);
// IBinder phoneServBinder = (IBinder) getServiceMethod.invoke(null,
// Context.TELEPHONY_SERVICE);
//
// Object telephonyObject = serviceMethod.invoke(null,
// new Object[] { phoneServBinder });
//
// // Check the phone is not in use first
// try {
// Method isOffhookMethod = myTelephonyClass
// .getMethod("isOffhook");
// Boolean isOffhook = (Boolean) isOffhookMethod
// .invoke(telephonyObject);
// if (isOffhook)
// return null;
// } catch (SecurityException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// // Get phone object
// String phoneFactoryName = "com.android.internal.telephony.PhoneFactory";
// Class phoneFactoryClass = Class.forName(phoneFactoryName);
//
// Method makeDefaultPhones = phoneFactoryClass.getMethod(
// "makeDefaultPhones", Context.class);
// makeDefaultPhones.invoke(null, Utils.context);
//
// Method getDefaultPhone = phoneFactoryClass
// .getMethod("getDefaultPhone");
// Object phoneObject = getDefaultPhone.invoke(null);
// return phoneObject;
// } catch (ClassNotFoundException e) {
// return null;
// } catch (NoSuchMethodException e) {
// return null;
// } catch (IllegalArgumentException e) {
// return null;
// } catch (IllegalAccessException e) {
// return null;
// } catch (InvocationTargetException e) {
// return null;
// } catch (SecurityException e) {
// return null;
// } catch (IllegalStateException e) {
// return null;
// }
// }

// private static void invokePhoneUtils(String methodName) {
// try {
// if (phoneObject == null)
// phoneObject = getPhoneObject();
//
// String phoneName = "com.android.internal.telephony.Phone";
// Class phoneClass = Class.forName(phoneName);
//
// // rejectCall
// Method rejectCallMethod = phoneClass.getMethod("rejectCall");
// rejectCallMethod.invoke(phoneObject);

// // Get getRingingCall method
// Method getRingingCallMethod = phoneClass
// .getMethod("getRingingCall");
// Object call = getRingingCallMethod.invoke(phoneObject);
//
// // Get Call Class
// String callClassName = "com.android.internal.telephony.Call";
// Class callClass = Class.forName(callClassName);
//
// // Get hung up method
// Method hungUpMethod = callClass.getMethod("hangup");
// hungUpMethod.invoke(call);

// // Get instance of phone utils
// Class phoneUtilsClass = null;
// if (phoneUtilsClass == null) {
// String phoneUtilsClassName = "com.android.phone.PhoneUtils";
// phoneUtilsClass = Class.forName(phoneUtilsClassName);
// }
//
// // Get static method
// Method telephonyMethod = phoneUtilsClass.getMethod(methodName,
// Object.class);
//
// // Method telephonyMethod = telephonyClass.getMethod(methodName);
// telephonyMethod.invoke(telephonyObject, phoneObject);

// } catch (ClassNotFoundException e) {
// } catch (NoSuchMethodException e) {
// } catch (IllegalArgumentException e) {
// } catch (IllegalAccessException e) {
// } catch (InvocationTargetException e) {
// } catch (SecurityException e) {
// } catch (IllegalStateException e) {}
// }

kaasnake
Freshman
Freshman
 
Posts: 2
Joined: Fri Jul 09, 2010 9:06 am

Re: Call blocking/forwarding.

Postby vicvondoom » Sat Aug 21, 2010 10:37 pm

User avatar
vicvondoom
Freshman
Freshman
 
Posts: 3
Joined: Sat Aug 21, 2010 10:12 pm

Top

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 6 guests