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

血红的双手。 提交于 2019-12-10 14:32:37

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/34858721/how-to-start-hidden-app-by-using-call-dialerkeypad-using-android-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!