首页 > 移动平台 > 详细

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

时间:2015-04-25 18:26:04      阅读:355      评论:0      收藏:0      [点我收藏+]

近日,写了一个有关设备信息的小应用,要求在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自己添加。



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

原文:http://blog.csdn.net/dkbdkbdkb/article/details/45271167

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!