Skip to content

Instantly share code, notes, and snippets.

@sanderversluys
Created March 9, 2012 13:44
Show Gist options
  • Save sanderversluys/2006546 to your computer and use it in GitHub Desktop.
Save sanderversluys/2006546 to your computer and use it in GitHub Desktop.
Secret Code Trick
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.widget.Toast;
public class MySecretBroadcastReceiver extends BroadcastReceiver {
public static final String DEBUG_KEY = "DEBUG";
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(DEBUG_KEY, !prefs.getBoolean(DEBUG_KEY, false));
editor.commit();
Toast.makeText(context, "DEBUG mode is set to " + prefs.getBoolean(DEBUG_KEY, false), Toast.LENGTH_LONG).show();
}
}
<receiver android:name="MySecretBroadcastReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code" android:host="3333" />
</intent-filter>
</receiver>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment