Android Run the application from Dialer

This is what I have so far, but nothing happens when I entered this combination in dialer

public class DialReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, final Intent intent) { if (intent.getAction().equals(android.content.Intent.ACTION_NEW_OUTGOING_CALL)) { String phoneNumber = intent.getExtras().getString( android.content.Intent.EXTRA_PHONE_NUMBER ); if(phoneNumber.equals("*#588637#")) { Intent intent1 = new Intent(context , Activity.class); intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK ); context.startActivity(intent1); } } } } 

and in androidmanifest

  <receiver android:name=".receiver.DialReceiver" android:exported="true" android:process=":background" tools:ignore="ExportedReceiver" > <intent-filter> <action android:name="android.intent.action.NEW_OUTGOING_CALL" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver> 
+7
source share
4 answers

Try with these small changes.

 String phoneNumber = intent.getExtras.getString("Intent.EXTRA_PHONE_NUMBER"); if(phoneNumber.equals("*#588637#")) { //do your stuff } 

And don't forget to add this line to the Manifest.xml file

 <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/> 

You may also find them useful.

+6
source

Does the receiver receive broadcasts at all? If not, you may have forgotten to enable the PROCESS_OUTGOING_CALLS permission.

+2
source

According to the 2nd ridoy link,

http://tikuflower.blogspot.com/2011/12/android.html

It should be

 String phoneNumber = intent.getStringExtra("android.intent.extra.PHONE_NUMBER"); 

but not

 String phoneNumber = intent.getExtras.getString("Intent.EXTRA_PHONE_NUMBER"); 

This change works for me at least ...

0
source

Try this,

Add to this in the manifest, here is host 12456, so your secret code is ## 123456 ## (dial the number on the dialing number)

 <receiver android:name=".Dialer"> //here is your broadcast receiver class <intent-filter> <action android:name="android.provider.Telephony.SECRET_CODE" /> <data android:scheme="android_secret_code" android:host="123456" /> </intent-filter> </receiver> 

here is your broadcast receiver class:

  class Dialer : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { // Declare Here your launcher activity in Intent var i : Intent = Intent(context, MainActivity::class.java) i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context!!.startActivity(i); } } 
0
source

All Articles