Run hidden application when secret code is dialed

My requirement is to launch a hidden application when the secret code is launched.

MainActivity.java

public class MainActivity extends
        BroadcastReceiver {

    String dialed_number;

    @Override
    public void onReceive(Context context, Intent intent)
    {
        dialed_number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);

        if(dialed_number.equals("*0*1235#"))
        {
            Intent appIntent = new Intent(context, MainActivity.class);
            appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(appIntent);
            setResultData(null);
        }
    }

}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tuto.bala.helloworld" >
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <receiver
            android:name=".MainActivity">
        </receiver>
    </application>

</manifest>

When I run the project, I get the following exception: connection problem invalid mmi android code

Can anybody help

Regards, Bala

+1
source share
2 answers

I used the same code that it works when we are given a dial number, this is a number that cannot be included *, #. and in the manifest file we have to declare the receiver this way

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

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

Just check out the edited code below:

Use BroadcastReceiver as follows:

public class MyOutgoingCallHandler extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        // Extract phone number reformatted by previous receivers
        String phoneNumber = 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=new Intent(context,MainActivity.class);
            i.putExtra("extra_phone", phoneNumber);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }    
    }
}

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

:

, , ,

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

, BroadcastReceivers , Right Number

0

: mmi android

, NEW_OUTGOING_CALL AndroidManifest.xml:

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

PROCESS_OUTGOING_CALLS :

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

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


All Articles