user4500
user4500

Reputation: 817

Android custom phone call keyboard

I want to develop an android application where I can call a number and then control a colorful light with the numbers 1 to 9 of the keyboard. Key 1 shows blue light, key 2 shows yellow light and so on...

With the normal phone keyboard it works fine. But I want a custom keyboard where I can see the colors of my remote light. I successfully created the colored keyboard. But now when I start the phone call, the original phone keyboard appears instead of my custom colorful keyboard.

I start the phone call like this:

Intent callIntent = new Intent(Intent.ACTION_CALL);  
callIntent.setData(Uri.parse("tel:555123456));  
startActivity(callIntent);  

How can I control a phone call with my custom keyboard?

Upvotes: 0

Views: 1049

Answers (1)

zoey
zoey

Reputation: 31

You may use java reflections to get the instance of com.android.intenal.telephony class to perform a call.

private void call(String number) {
    Class<TelephonyManager> c = TelephonyManager.class;
    Method getITelephonyMethod = null;
    try {
        getITelephonyMethod = c.getDeclaredMethod("getITelephony",
                (Class[]) null);
        getITelephonyMethod.setAccessible(true);
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    try {
        TelephonyManager tManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        Object iTelephony;
        iTelephony = (Object) getITelephonyMethod.invoke(tManager,(Object[]) null);
        Method dial = iTelephony.getClass().getDeclaredMethod("call", String.class);
        dial.invoke(iTelephony, number);
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

Upvotes: 3

Related Questions