molds
molds

Reputation: 71

SECRET_CODE set from code Android

I know how to work with Secret code from Manifest file, it is working well with this source code:

 <receiver android:name="receivers.SecretCodeReceiver">
        <intent-filter>
            <action android:name="android.provider.Telephony.SECRET_CODE" />


            <data
                android:host="666"
                android:scheme="android_secret_code" />

        </intent-filter>
    </receiver>

But, how i can change host from source code ? Is it possible ? I tried this one:

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

But no luck.

Upvotes: 3

Views: 2659

Answers (1)

Jigar Shekh
Jigar Shekh

Reputation: 2810

Modify Manifest.xml file

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

And modify your Broadcast Receiver class

if(intent.getAction().equals("android.provider.Telephony.SECRET_CODE")) {
        String uri = intent.getDataString();
        String[] sep = uri.split("://");
        if (sep[1].equalsIgnoreCase("1234")) {
            Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.whatsapp");
            context.startActivity(launchIntent);
        } else if (sep[1].equalsIgnoreCase("5678")) {
            Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("net.one97.paytm");
            context.startActivity(launchIntent);
        } 
    }

Now dial number from dialer*#*#NUMBER#*#* eg.*#*#1234#*#* for launch whatsapp

Upvotes: 4

Related Questions