暗码启动
- packages/apps/Contacts/src/com/android/contacts/SpecialCharSequenceMgr.java
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 >##* 这样的指令时,程序会对外发送广播。
拨号盘启动
注册广播
<receiver android:name=".broadcast.PhoneBroadcastReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE"/>
<data
android:host="8888"
android:scheme="android_secret_code"/>
</intent-filter>
</receiver>
广播启动
public static final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE";
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case SECRET_CODE_ACTION:
Uri uri = intent.getData();
if(uri != null){
String host = uri.getSchemeSpecificPart().substring(2);
if("8888".quals(host)){
//启动应用
Intent intent = new Intent(context, LoginActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
break;
}
}
}
通过代码发广播拉起暗码
系统权限
androi:sharedUserId="android.uid.system"
发送广播
Intent intent = new Intent("android.provider.Telephony.SECRET_CODE", Uri.parse("android_sercret_code://8888"));
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
this.sendBraodcast(tntent, null);