Programmatically enter secret code like *#*#4636#*#* on Android

try this

String ussdCode = "*" +Uri.encode ("#")+"*"+Uri.encode ("#")+ "4636" + Uri.encode ("#")+"*"+Uri.encode ("#")+"*";
startActivity (new Intent ("android.intent.action.CALL", Uri.parse ("tel:" + ussdCode)));

finally you must encode '#' using Uri.encode()


Secret codes exist and work independent of the dialer application. The dialer application just provides a handy interface for these codes. It recognizes the special string and then calls a special intent to invoke the action. You shouldn't use the dialer to call these dialogs. Instead you can call the secret codes directly yourself like the dialer does internally:

Invoking built in secret codes:

What the dialer really does when you enter the code is extracting the number between *#*# and #*#* and then broadcasting the following intent:

sendBroadcast(new Intent("android.provider.Telephony.SECRET_CODE", Uri.parse("android_secret_code://4636")));

Register your own secret codes (if you like):

You can even register your own secret code actions using:

<action android:name="android.provider.Telephony.SECRET_CODE" /> 
<data android:scheme="android_secret_code" android:host="4636" /> 

Source: http://android.amberfog.com/?p=422

Edit: Fixed a bug in the original code (see comment)


Is it also possible to open this stuff programmatically?

Yes:

    Intent in = new Intent(Intent.ACTION_MAIN);
    in.setClassName("com.android.settings", "com.android.settings.TestingSettings");
    startActivity(in);

You just need to watch logcat output to learn what this magic combination actually opens:

I/ActivityManager(31362): START {act=android.intent.action.MAIN flg=0x10000000 cmp=com.android.settings/.TestingSettings} from pid 4257

Tags:

Android