场景设想:如果你需要隐藏你的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也可以用来区分程序的不同模式;