intent

Rss feed of the tag

Secret Phone number

Written by Xavier Gouchet - 14 august 2013 - no comments

So maybe you already know that some secret phone numbers are hidden in Android. For instance, if you dial *#*#4636#*#* on your Android phone1, you'll access a secret settings panel.

But did you know that you can add this feature in your own android application ? Basically, you can setup a BroadcastReceiver to listen to a secret number and then launch a hidden Activity. This can be used to unlock some beta features or access developper options on your app. Or just add an easter egg to your phone.

To do that, you simply need to declare your BroadcastReceiver in your manifest, like this :

    <!-- Secret receiver -->
    <receiver android:name=".MySecretBroadcastReceiver" >
        <intent-filter>
            <action android:name="android.provider.Telephony.SECRET_CODE" />
            <data
                android:host="1337"
                android:scheme="android_secret_code" />
        </intent-filter>
    </receiver>

After that, you simply need to handle the corresponding Intent in your BroadcastReceiver :


public class MySecretBroadcastReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		if (intent.getAction().equals("android.provider.Telephony.SECRET_CODE")) {
			// Do something in here
		}
	}

}

Enabling / Disabling activities at runtime

Written by Xavier Gouchet - 20 february 2013 - no comments

Sometimes, you might want an activity to be available only under specific conditions. But you may want to completely disable it at runtime when some conditions are met. For instance based on the time, or the user geolocation.

This could also let one have different activities based on the user's configuration

You can do so simply by using the PackageManager. In the following example, I disable an activity and enable another one.


PackageManager pm = getPackageManager();
pm.setComponentEnabledSetting(new ComponentName(this, ActivityC.class), 
    PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 0);
pm.setComponentEnabledSetting(new ComponentName(this, ActivityA.class), 
    PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);

The manifest declares the two activities with the same intent filter, namely the home screen shortcut. But using the previous code, I'm able to get a single one of them in the launcher menu at any given time.

A developer tool : Intent Intercept

Written by Xavier Gouchet - 09 november 2012 - no comments

One of the greatest idea in the Android framework is the concept of Intents, which let potentially any application interact with any other application, without any of them knowing explicitly the other.

The best example is the "share" intent. When you click the Share button on an application, an Intent is created, with a Action named "ACTION_SEND", and maybe some data embedded in it. Then Android tries to find all application who declare themselves as able to handle an Intent with the "ACTION_SEND" action, and let you choose which one to use.

Share intent - Application chooser

Intent Intercept is a pretty usefull app to know what intent is used for a specific action in an application. When an implicit intent is launched on the device, you'll always have the option to handle it with Intent Intercept which will then analyse the intent's content for you.

Intent Intercept

As always, you can download it from the Google Play Store.