做android也很长时间了,在论坛上做潜水员也很久了,再潜就真的变潜水艇了,废话少说,现在就开始我们的android学习的第一篇《android暗码》,本文是基于froyo源码
在拨号盘界面输入*#*#info#*#*会进入android系统自带的工程模式,里面有一些网络相关的信息,系统是怎么调用的呢?
在拨号盘输入号码时,调用TwelveKeyDialer类实现接口TextWatcher的方法afterTextChanged()---只要有变化就会调用这个方法。接着调用SpecialCharSequenceMgr类的静态方法handleChars,
其中会有调用4个方法:
if (handleIMEIDisplay(context, dialString)//*#06#显示IMEI号码 || handlePinEntry(context, dialString, pukInputActivity)// PIN/PIN2/PUK/PUK2-related || handleAdnEntry(context, dialString)//获取sim卡上的记录 || handleSecretCode(context, dialString)) {//暗码处理---格式为*#*#<code>#*#* |
在函数handleSecretCode中:
Intent intent = new Intent(Intents.SECRET_CODE_ACTION, Uri.parse("android_secret_code://" + input.substring(4, len - 4))); context.sendBroadcast(intent);//广播Intent |
了解上述代码之后再回到自己的应用程序中的androidmanifest.xml中能找到如下代码:
<receiver android:name = “AaaBbbCcc”> <intent-filter> <action android:name = “android.provider.Telephony.SECRET_CODE”/> <data android:scheme = “anroid_secret_code” android:host = “1234”/> </intent-filter> </receiver> |
当按下*#*#1234#*#*时, AaaBbbCcc(继承于BroadcastReceiver)的方法onReceive被调用,从而实现你想实现的功能。