Powered by Blogger.
Have you ever thought about using hidden Android™ APIs? A few weeks ago, Erik Hellman from Sony Ericsson’s Technology research department presented a few examples of how these APIs could be used at Droidcon in London, and at Mobile Monday in Bucharest. We have now made Erik’s hidden API code examples available for download.
Download and learn more after the jump.
In every Android release, there are a large number of hidden APIs available. The hidden APIs can be used by applications, but they are not very easy to find unless you know what you are looking for. The reason to hide certain APIs may differ. Some may not be regarded as stable enough to promote, others may be subject to change. Several other reasons may exist. Nonetheless, by knowing about these APIs, you definitely have the chance to get ahead of your competition by creating some unique hidden API-based functionality in your apps.
The hidden API code examples, created by Erik Hellman, consist of four different examples. Find out more about them below.
ReadSMS code example
This is a small code example that is intended to show how an application can read the internal SMS database. The hidden part here is the content URI to the SMS database: “content://sms/inbox”. This code example only requires the following permission to read SMS: “android.permission.READ_SMS”.
Tethering code example
This code example demonstrates how an app can use Wi-Fi with the Java reflection methods. This code example must be signed with a system certificate, and it must also share the User Id with the system. The system User Id is declared shared by declaration in the Android manifest:

package="com.sonyericsson.tetheringdemo"

android:sharedUserId=="android.uid.system"

android:versionCode="1"

android:versionName="1.0">
This code example also requires a set of Wi-Fi permissions:











The hidden API here is the broadcast intent: “android.net.wifi.WIFI_AP_STATE_CHANGED”. This is received by the broadcast receiver in the project. The hidden method in this class is called setWifiApConfiguration and it is reached using the Java reflection method in that class.
WifiConfiguration config = new WifiConfiguration();

config.SSID = "EriksOpenWifi";

config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);

String setWifiApConfigurationMethodName = "setWifiApConfiguration";

Method setWifiApConfigurationMethod = wifiManager.getClass().getMethod(setWifiApConfigurationMethodName, WifiConfiguration.class);

result = (Boolean) setWifiApConfigurationMethod.invoke(wifiManager, config);
This code snippet is used to reach this code:
public boolean setWifiApConfiguration(WifiConfiguration wifiConfig) {

try {

mService.setWifiApConfiguration(wifiConfig);

return true;

} catch (RemoteException e) {

return false;

}

}
Overlay and Touch input code examples
These two code examples work together in order to demonstrate how to do touch input and how to draw a window on top of the currently active window. These code examples need system permissions, and must be run as system user.

android:sharedUserId="android.uid.system"

package="com.sonyericsson.overlaydemo"

android:versionCode="1"

android:versionName="1.0">
The two things requiring system privileges are the permission “.provider.Telephony.SMS_RECEIVED” and the direct interface to the window manager. To use the code example requiring the system certificate, you need to sign your apps with the keys of the system certificate. To try this, you can use a phone with a custom ROM.
Feedback and learning more
These are some examples showing how you can work with hidden APIs. To learn more, there are several resources available online. We especially recommend the five part hidden API introduction available at DevMaze. Here, you will not only learn how to work more with hidden APIs, but also how to get it to work in different phones.
Feel free to comment and ask questions on this topic, Erik Hellman and the rest of the Engineering team will try to answer your questions as soon as possible. What potential uses do you see in utilising these hidden APIs?