Skip to content Skip to sidebar Skip to footer

Launch Hidden App When Secret Code Is Dialed

my requirement is to launch an hidden app when a secret code is dailed. MainActivity.java public class MainActivity extends BroadcastReceiver { String dialed_number;

Solution 1:

I have used same code it's working when we are given dial number is a number not to include *,#. and in Manifest file we have to declare the receiver like this

<receiverandroid:name=".MainActivity" ><intent-filter><actionandroid:name="android.intent.action.NEW_OUTGOING_CALL" /></intent-filter></receiver>

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

Just see the below edited code:

Use the BroadcastReceiver as follows:

publicclassMyOutgoingCallHandlerextendsBroadcastReceiver {

    @OverridepublicvoidonReceive(Context context, Intent intent) {
        // Extract phone number reformatted by previous receiversStringphoneNumber= getResultData();
        if (phoneNumber == null) {
            // No reformatted number, use the original
            phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
        }

        if(phoneNumber.equals("1234")){ // DialedNumber checking.// My app will bring up, so cancel the broadcast
            setResultData(null);

            // Start my app
            Intent i=newIntent(context,MainActivity.class);
            i.putExtra("extra_phone", phoneNumber);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }    
    }
}

Don't forget to register this receiver in your manifest

<receiverandroid:name="MyOutgoingCallHandler"><intent-filter ><actionandroid:name="android.intent.action.NEW_OUTGOING_CALL"/></intent-filter></receiver>

Also, include the permission:

Now, if you are ignoring the number checking in receiver, you'll get dialed number inside your MainActivity,

String phone=getIntent().getStringExtra("extra_phone");
    if(!phone.equals(null)){
        Toast.makeText(getBaseContext(), phone, Toast.LENGTH_LONG).show();
    }

If you want to launch app as call to magic number, it's quite simple using BroadcastReceivers for outgoing call, you can get solution from Right Number app

Solution 2:

exception: connection problem invalid mmi code android

To detect outgoing phone call event you should register broadcast with NEW_OUTGOING_CALL Action in AndroidManifest.xml :

<receiverandroid:name=".MainActivity"><intent-filter><actionandroid:name="android.intent.action.NEW_OUTGOING_CALL" /></intent-filter></receiver>

and also add PROCESS_OUTGOING_CALLS permission :

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

Post a Comment for "Launch Hidden App When Secret Code Is Dialed"