Reputation: 71
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
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