一、我们这里就举例一个输入指令*#08#去开启Android中的工程模式测试应用(FactoryTest);既然要通过拨号盘输入指令,我们这里就要去监听拨号盘的输入。
1.vendor/mediatek/proprietary/packages/apps/Dialer/java/com/android/dialer/dialpadview/SpecialCharSequenceMgr.java
(1).我们先在文件中定义指令
private static final String FACTORY_CHECK = "*#08#";
(2).编写指令监听函数
private static boolean handleFactoryTest(Context context, String input) {
if (input.equals(FACTORY_CHECK )) {
Log.d(TAG, "handleTeeResultDisplay() sending intent to factorytest app");
Intent showTeeResultIntent = new Intent();
showTeeResultIntent.setComponent(
new ComponentName("com.mediatek", "com.mediatek.MainActivity"));
try {
context.startActivity(showTeeResultIntent);
} catch (ActivityNotFoundException e) {
Log.e(TAG, "startActivity() failed: " + e);
}
return true;
}
return false;
}
(3).在public static boolean handleChars(Context context, String input, EditText textField)中调用
public static boolean handleChars(Context context, String input, EditText textField) {
// get rid of the separators so that the string gets parsed correctly
String dialString = PhoneNumberUtils.stripSeparators(input);
//mag-sk change anim 190311
handleCustomAnim(context, dialString);
if (handleDeviceIdDisplay(context, dialString)
|| handleRegulatoryInfoDisplay(context, dialString)
|| handlePinEntry(context, dialString)
|| handleAdnEntry(context, dialString, textField)
|| handleSecretCode(context, dialString)
|| handleFactoryTest(context, dialString) //add
/// M: for plug-in @{
|| ExtensionManager.getDialPadExtension().handleChars(context,
dialString)) {
/// @}
return true;
}
if (MotorolaUtils.handleSpecialCharSequence(context, input)) {
return true;
}
return false;
}