SECRET_CODE installed with Android code

I know how to work with secret code from a manifest file, it works 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 can I change the host from the source code? Is it possible? I tried this:

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

But no luck.

+1
source share
1 answer

Modify the 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 change the 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 the number from the dialer *#*#NUMBER#*#*for example. *#*#1234#*#*to run whatsapp

+2
source

Source: https://habr.com/ru/post/1649312/


All Articles