比如在拨号面板中输入*#*#55555#*#*启动没有图标的应用,其包名和类名是com.zms.test/.Main
在计算器中输入55555然后按=,也启动这个应用。可以通过以下方式实现:
首先是拨号:
修改文件packages/apps/Dialer/src/com/android/dialer/SpecialCharSequenceMgr.java
@@ -66,6 +66,7 @@ public class SpecialCharSequenceMgr { private static final String MMI_IMEI_DISPLAY = "*#06#"; private static final String DEVICE_TEST = "*#66#"; + private static final String ZMS_MODE = "*#*#55555#*#*"; private static final String MMI_REGULATORY_INFO_DISPLAY = "*#07#"; private static String PROJECT_NAME = SystemProperties.get("ro.esky.target.project"); @@ -158,6 +159,13 @@ public class SpecialCharSequenceMgr { return true; } + if (input.equals(ZMS_MODE)) { + Intent intent = new Intent(); + intent.setComponent(new ComponentName("com.zms.test","com.zms.test.Main")); + context.startActivity(intent); + return true; + } + if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) { Intent intent = new Intent(TelephonyIntents.SECRET_CODE_ACTION, Uri.parse("android_secret_code://" + input.substring(4, len - 4)));
然后看一下计算器的:
修改文件packages/apps/Calculator/src/com/android/calculator2/Logic.java
import org.javia.arity.Symbols; import org.javia.arity.SyntaxException; +import android.app.Activity; +import android.content.ComponentName; +import android.content.Intent; class Logic { private CalculatorDisplay mDisplay; private Symbols mSymbols = new Symbols(); @@ -41,6 +44,7 @@ class Logic { private int mLineLength = 0; private static final String INFINITY_UNICODE = "\u221e"; + private static final String ZMS_NUMBER = "55555"; public static final String MARKER_EVALUATE_ON_RESUME = "?"; @@ -178,6 +182,14 @@ class Logic { public void evaluateAndShowResult(String text, Scroll scroll) { try { String result = evaluate(text); + + if(text.equals(ZMS_NUMBER)) + { + Intent intent = new Intent(); + intent.setComponent(new ComponentName("com.zms.test","com.zms.test.Main")); + mContext.startActivity(intent); + } + if (!text.equals(result)) { mHistory.enter(text); mResult = result;
转载请注明出处:周木水的CSDN博客 http://blog.csdn.net/zhoumushui
我的GitHub:周木水的GitHub https://github.com/zhoumushui
时间: 2024-10-18 00:22:00