Android 拨号盘暗码启动应用程序

近日,写了一个有关设备信息的小应用,要求在launcher中不可显,通过拨号键盘暗码启动该应用。现将心得记录如下:

软件平台:Android4.4.3

首先,要在AndroidManifest.xml中注册接收android暗码广播。

        <span style="font-size:18px;"><receiver android:name="InfoSecretCode" >
            <intent-filter>
                <action android:name="android.provider.Telephony.SECRET_CODE" />
                <data
                    android:host="668866"
                    android:scheme="android_secret_code" />
            </intent-filter>
        </receiver></span>

其次,需要实例化对接收广播事件的处理,取名为InfoSecretCode.java,代码如下:

<span style="font-size:18px;">import android.content.Context;
import android.content.Intent;
import android.content.BroadcastReceiver;
import android.util.Config;
import android.util.Log;
import android.view.KeyEvent;

public class InfoSecretCode extends BroadcastReceiver {
    private final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE"; 
    public InfoSecretCode() {
    }

    @Override  
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(SECRET_CODE_ACTION)) {
            Intent i = new Intent(Intent.ACTION_MAIN);
            i.setClass(context, InfoActivity.class);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }
    }
}</span>

如此,在拨号键盘输入“*#*#668866#*#*”即可弹出InfoActivity了,具体activity自己添加。



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值