场景设想:如果你需要隐藏你的apk icon,并通过android的拨号盘启动你的apk应用
以下是定义了*#*#(……)#*#*格式以及*#(……)*#格式;类似的输入格式都会广播SECRET_CODE_ACTION,
- <span xmlns="http://www.w3.org/1999/xhtml">/**
- * 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;
- }</span>
<span xmlns="http://www.w3.org/1999/xhtml">/**
* 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;
}</span>
指定你的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>