Mohamed Tahar Zwawa
Mohamed Tahar Zwawa

Reputation: 123

How to launch an android service from a custom call number

I'm developing an Android application, i have a service running in background that i want to lauch it by introducing a custom ussd number. For example when i call #12345# my service starts.Thank you in advance

Upvotes: 0

Views: 561

Answers (1)

Bryan Herbst
Bryan Herbst

Reputation: 67189

You can register a BroadcastReceiver in your manifest that listens for android.provider.Telephony.SECRET_CODE intents. You also specify the secret code in the manifest.

For example, this manifest entry registers MyBroadcastReceiver for the secret code *#*#12345#*#*.

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

MyBroadcastReceiver should look something like this:

public class MyBroadcastReceiver extends BroadcastReceiver {
    public void onReceive(Context context, Intent intent) {
        // Create an intent to start your Service.
    }
}

Upvotes: 2

Related Questions