質問

I am a beginner in android programming. I want to use the hidden method "getState()" of "com.android.internal.telephony.call" package to manage the state of an outgoing call such as activating, ringing, answering, rejecting and disconnecting. But there is an error in the following code on the line indicated by "**".

Any help?

My code is :

import com.android.internal.telephony.*;
public class MainActivity extends Activity {
Class myclass;
ClassLoader cloader;
Method f;
Object o;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    cloader = this.getClass().getClassLoader();
    try {
        myclass = cloader.loadClass("com.android.internal.telephony.Call");
        // No error generated. "Call" class will be loaded.
    }
    catch (Exception e)
    {
        System.out.println(e.toString());
    }
    try {
        f = myclass.getMethod("getState", null);
        // No error generated.Method "f" will be assigned
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    Constructor constructors[] = myclass.getDeclaredConstructors();
    // There is one constructor only
    Constructor constructor = null;
    for (int i=0; i<constructors.length;i++)
    {
        constructor = constructors[i];
        if (constructor.getGenericParameterTypes().length == 0)
            break;
        }
    constructor.setAccessible(true);
    try {
            o = constructor.newInstance(null);
    //*****an exception generated here.
    //*****Exception is "java.lang.instantationexception"
    }
    catch (Exception e) {
        System.out.println(e.toString());
        }
    try {
        f = myclass.getMethod("getState", null);
        // No error
        } catch (Exception e) {
            System.out.println(e.toString());
            }
    }
役に立ちましたか?

解決

Don't try to call private members like this. It will not work across Android versions and even across manufacturer customized ROMs of the same version.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top