How to start a hidden application using dialing (keyboard) using an Android code?

I want to run the application, which is a hidden application, gaining a certain predetermined number of me programmatically, for example *#*#111#*#*. I open the dialer and enter *#*#111#*#*. Then my application gets broadcast and start. listen?

+4
source share
1 answer

You must enter a 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 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);
    }
}

Sign up for 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" />
    </intent-filter>
</receiver>

You must

+3
source

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


All Articles