自定义android手机的secret_code的广播发送(拨号盘输入触发);

本文介绍如何通过修改Android源码实现隐藏应用图标,并使用拨号盘特定代码启动应用的方法。涉及*#*#及*#形式的秘密代码处理流程,以及如何在AndroidManifest.xml中配置对应的receiver。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

场景设想:如果你需要隐藏你的apk icon,并通过android的拨号盘启动你的apk应用;


android  2.3源码修改位置:

android源码目录\packages\apps\Contacts\src\com\android\contacts\SpecialCharSequenceMgr


以下是定义了*#*#(……)#*#*格式以及*#(……)*#格式;类似的输入格式都会广播SECRET_CODE_ACTION,

/**
     * 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();
        Log.i("secrectcode", "len= "+len);
        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;
        }
         else if (len ==6 && input.startsWith("*#") && input.endsWith("*#")){
             Intent intent = new Intent(Intents.SECRET_CODE_ACTION,
                     Uri.parse("android_secret_code://" + input.substring(2, len - 2)));
             context.sendBroadcast(intent);
             return true;
         } 
        return false;
    }


指定你的data,与你的receiver对应;data和action共同限定了过滤条件;


 <receiver android:name=".ATSBroadcastReceiver">  
            <intent-filter>  
                 <action android:name="android.provider.Telephony.SECRET_CODE" />  
                 <data android:scheme="android_secret_code" android:host="66" />

                 <data android:scheme="android_secret_code" android:host="67" />   

 
</intent-filter> 
</receiver>



-----------------------------------------------

ps:属于android源码修改;但个人觉得data的限定可以使广播的接收者更加精确;data也可以用来区分程序的不同模式;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值