简体   繁体   中英

Call a method in android system app

I am developing an android application where I want to call a method in android system app(Phone app) to access some of the features. I checked few examples to understand how method calling is happening within system apps. We need to import the package and then create a instance of the class to access specific methods.

But when I use the same way, it says "Package can't be resolved".

My question is can we access methods in android system app? If so what is the best way of doing it?

If you are trying to invoke a private api in android library or from system apps, the only way to do that is by using reflection.

http://code.tutsplus.com/tutorials/learn-java-for-android-development-reflection-basics--mobile-3203

String sClassName = "android.content.Intent";
try {
    Class classToInvestigate = Class.forName(sClassName);
    String strNewFieldName = "EXTRA_CHANGED_PACKAGE_LIST";
    Field newIn22 = classToInvestigate.getField(strNewFieldName);

} catch (ClassNotFoundException e) {
    // Class not found
} catch (NoSuchFieldException e) {
    // Field does not exist, likely we are on Android 2.1 or older
    // provide alternative functionality to support older devices
} catch (SecurityException e) {
    // Access denied!
} catch (Exception e) {
    // Unknown exception
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM