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

软件平台:Android4.4.3

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

                                                                        

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

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);        }    }}

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



更多相关文章

  1. android 混淆配置 实例实战项目讲解
  2. Android 只开启一个Activity实例
  3. OpenCV android sdk配置OpenCV android NDK开发实例
  4. AIDL实例分析和讲解
  5. Android常用实例—Alert Dialog的使用
  6. Android的Activity加载方式实例分析
  7. Android中Json应用实例介绍
  8. [置顶] 我的Android进阶之旅------>Android Service学习之AIDL,

随机推荐

  1. Android测试用例执行线程和UI线程
  2. Android开发时提示Your project contains
  3. android文件系统
  4. android input及简单am命令
  5. Android 网络框架学习之Retrofit
  6. Android(安卓)SSL BKS证书的生成过程
  7. Android(安卓)where 长度限制
  8. 使用大量checkbox的时候可能出现的小问题
  9. [cocos2d-x 学习] Windows下环境配置
  10. Android访问中央气象台的天气预报API得到