subtleseeker
subtleseeker

Reputation: 5273

Using SECRET_CODE from android.provider.Telephony

I want to implement a basic idea to make a balance sheet in android. If I write *#*#1234#*#* on my number dial screen then it must simply increment 34 in my app(or maybe in a text file). In search to implement this idea, I came across android.provider.Telephony.SECRET_CODE.

What I want is to read any number like *#*#<number>#*#* from the dialpad of phone. So I want my code to run in a way such that it identifies any code of this format as the secret code: *#*#12$$#*#*. I suppose it is hard to think if there is any way in which it can work, but if anybody knows anything, I would be very curious to know. Thanks a lot in advance!

Upvotes: 6

Views: 7926

Answers (1)

Pierre
Pierre

Reputation: 9072

http://blog.udinic.com/2013/05/17/create-a-secret-doorway-to-your-app

Check this link out.

Here is a sample piece of code. In your manifest, declare your receiver and with a secret code for example: 111222

<receiver android:name=".receiver.DiagnoserReceiver">
    <intent-filter>
        <action android:name="android.provider.Telephony.SECRET_CODE"/>
        <data android:scheme="android_secret_code" android:host="111222"/>
    </intent-filter>
</receiver>

Then create the receiver:

public class DiagnoserReceiver extends BroadcastReceiver {

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

I suppose if you want multiple numbers, you can add the variants of codes that your app will listen for:

<intent-filter>
    <action android:name="android.provider.Telephony.SECRET_CODE"/>
    <data android:scheme="android_secret_code" android:host="111222"/>
    <data android:scheme="android_secret_code" android:host="1234"/>
    <data android:scheme="android_secret_code" android:host="1235"/>
    <data android:scheme="android_secret_code" android:host="1236"/>
    <data android:scheme="android_secret_code" android:host="1237"/>
</intent-filter>

EDIT:

You can try this SO post I found

only to match the beginning of host. The rules are these:

  • Put * as the first character of the host.
  • Write the rest of of the host until the end.
android:host="*site.com"
android:pathPattern=".*"
android:scheme="http" />

It will catch links of:

  • www.site.com
  • site.com
  • mail.site.com

So you should be able to wildcard the font of the

<data android:scheme="android_secret_code" android:pathPattern="*" android:host="*34"/>

In theory it should work for 0034 ... 9934

**CAUTION: **

Anyone can decompile your app and see the codes in the manifest file. So whatever you do, make sure it is secured. IE. If you open an activity from the receiver, make sure the activity asks for a password first.

OR

Another way to be more safe is to register the broadcast receiver in your MainApplication class in onCreate - add intentFilters to your liking, this way your codes are not exposed in the android manifest file but it will not work if your app is completely closed or swiped away. Simply open the app, (wait for the broadcast receiver to register), minimise it, type in your code, and voila.

Upvotes: 6

Related Questions