Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 310
user5072303 Avatar asked Jan 18 '16 15:01

user5072303


1 Answers

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

like image 56
tiny sunlight Avatar answered Sep 28 '22 15:09

tiny sunlight