手机拨号启动隐藏程序

       最近做一个出厂测试的程序,因为不能直接显示到程序列表中,因此需要将程序隐藏,再通过拨打*#*#xxxx#*#*来启动程序。在这里和大家分享分享。

一.先看看Android源码 (笔者参考的是Android2.3)。

        联系人模块中有一个文件 packages/apps/Contacts/src/com/android/contacts/SpecialCharSequenceMgr.java,相关代码段为

/**
     * Handles secret codes to launch arbitrary activities in the form of *#*#<code>#*#*.
     * If a secret code is encountered an Intent is started with the android_secret_code://<code>
     * URI.
     *
     * @param context the context to use
     * @param input the text to check for a secret code in
     * @return true if a secret code was encountered
     */
    static boolean handleSecretCode(Context context, String input) {
        // Secret codes are in the form *#*#<code>#*#*
        int len = input.length();
        if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) {
            Intent intent = new Intent(Intents.SECRET_CODE_ACTION,
                    Uri.parse("android_secret_code://" + input.substring(4, len - 4)));
            context.sendBroadcast(intent);
            return true;
        }

        return false;
    }
       这里,在拨号中已经做了处理,当收到 *#*#<code>#*#* 时,程序会发送广播,那么我们只需要接收这个广播再去做相应处理就OK了。

二.定义相应的广播接收器。

package com.xxx.ftest;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

public class SecretLaunchReceiver extends BroadcastReceiver {
	
	public static final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE";
	
	/**
	 * the uri is like : android_secret_code://1234
	 */
	@Override
	public void onReceive(final Context context, Intent intent) {
		if (intent.getAction().equals(SECRET_CODE_ACTION)) {
			Uri uri = intent.getData();
			System.out.println("SecretLaunchReceiver onReceive: " + uri);
			if(uri != null){
				String content = uri.getSchemeSpecificPart().substring(2);
				if("0755".equals(content)){
					Intent i = new Intent(context, ModeChooserActivity.class);
					i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
					context.startActivity(i);
				}
			}
		}
	}
}


 三.在自己程序的Manifest文件中,注册广播接收器。

<receiver android:name="com.xxx.ftest.SecretLaunchReceiver" >
       <intent-filter>
           <action android:name="android.provider.Telephony.SECRET_CODE" />
           <data android:scheme="android_secret_code" />
       </intent-filter>
</receiver>

        OK,打完收工,这样只要在拨号中输入 *#*#0755#*#*就可以启动自己的程序了。

原文地址:http://blog.csdn.net/ville_zeng/article/details/19496569, 欢迎转载!




  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值