Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, Is it possible to run the app from dialer?

Tags:

android

I need (if its possible) to add an ability to my project to be run when user enters a code such as #1234# in dialer. I'm not sure it is possible. Currently when i lunch my app from application folder it starts but just for fun i want to know can i lunch it with a code?

like image 793
Hesam Avatar asked Feb 22 '12 07:02

Hesam


1 Answers

You can start your application activity class by dialer but for that your app should running in background. for that you should implement a class which extends to BroadcastReceiver. follow this reference code.

public class Example extends BroadcastReceiver 
{

    @Override
    public void onReceive(Context context, final Intent intent) {

      if (intent.getAction().equals(android.intent.action.NEW_OUTGOING_CALL)) {
       String phoneNumber = intent.getExtras().getString( android.intent.extra.PHONE_NUMBER );

         if(phoneNumber.equals("#1234#")) { 
            Intent intent1 = new Intent(context , YourActivity.class);
            intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK );
            context.startActivity(intent1);
       }

      }

    }

} 
like image 127
Priyank Patel Avatar answered Nov 14 '22 03:11

Priyank Patel