How to start hidden app by using call dialer(keypad) using Android code?

user5072303 picture user5072303 · Jan 18, 2016 · Viewed 12.8k times · Source

I want to start my app which is a hidden app by dialing certain predfined number by me programatically ,for eg *#*#111#*#*.I open the dialer and input *#*#111#*#*.Then My app receives the broadcast and starts.Which broadcast should I listen?

Answer

tiny sunlight picture tiny sunlight · Jan 18, 2016

You should input number *#*#xxxx#*#*, say, *#*#110#*#*.

Create a Receiver:

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

public class Listener extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

String pwd = intent.getData().getHost();

Intent i = new Intent(context, CalllistenerActivity.class);

i.putExtra("data", pwd);

i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

context.startActivity(i);

}

}

Create an Activity:

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class CalllistenerActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);
        String pwd = getIntent().getStringExtra("data");
        tv.setText(TextUtils.isEmpty(pwd)?"Plz input *#*#123#*#* in dial" :pwd);
        setContentView(tv);
    }
}

Register in AndroidManifest:

<activity android:name=".CalllistenerActivity" android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<receiver android:name="Listener">
    <intent-filter>
        <action android:name="android.provider.Telephony.SECRET_CODE" />
        <data android:scheme="android_secret_code" android:host="110"/>
    </intent-filter>
</receiver>

You should