1.AndroidManifest.xml 添加暗码,并添加注册receiver:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mediatek.engineermode" android:sharedUserId="android.uid.phone" android:versionCode="1" android:versionName="1.0" > <application android:label="@string/app_name" android:theme="@android:style/Theme.Holo"> <receiver android:name=".VersionCheckReceiver"> <intent-filter> <action android:name="android.provider.Telephony.SECRET_CODE" /> <data android:host="888888" android:scheme="android_secret_code" /> </intent-filter> </receiver> </application> </manifest>
package com.mediatek.engineermode; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.widget.Toast; import android.util.Log; public class VersionCheckReceiver extends BroadcastReceiver{ private static final String TAG = "VersionCheckReceiver"; @Override public void onReceive(Context context, Intent intent) { VersionCheck(context); } private void VersionCheck(Context context) { Toast.makeText(context, "Surplus Baseline Code", Toast.LENGTH_SHORT).show(); } }
3.暗码格式定制 参照文件:SpecialCharSequenceMgr.java
/** * 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 private 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(TelephonyIntents.SECRET_CODE_ACTION, Uri.parse("android_secret_code://" + input.substring(4, len - 4))); context.sendBroadcast(intent); return true; } return false; }