目的:****在拨号键盘输入 *#*#5201314#*#* 启动自定义的某个(隐藏)应用,大胆说出你的爱!
1. 修改Android源码dialer 相关代码,自定义android_secret_code并在afterTextchanged函数中发出处理广播:
vim packages/apps/Dialer/src/com/android/dialer/dialpad/DialpadFragment.java
+ private final String LOVEU = "*#5201314#*";
@Override
public void afterTextChanged(Editable input) {
+ if(LOVEU.equals(input.toString())){
+ startLove();
+ mDigits.getText().clear();
+ }
+ // After user put the number do it
+ private void startLove(){
+ Intent intent = new Intent();
+ intent.setAction("com.ckt.cxuef.loveu");
+ intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ try{
+ // Call the Receiver
+ startActivity(intent);
+ }catch(ActivityNotFoundException ane){
+ ane.printStackTrace();
+ }
+ }
2. 修改Android工程App的AndroidManifest.xml ,定义接收广播:
<receiver
android:name=".LoveUReceiver"
android:exported="true" >
<data
android:host="5201314"
android:scheme="android_secret_code" />
3. 增加Android工程App的XXXReceiver,继承并实现广播BroadcastReceiver:
public final class LoveUReceiver extends BroadcastReceiver {
private static final String TAG = "EIROT_SECRET_CODE";
private static final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE";
// process *#*#5201314#*#*
private final Uri mLoveUri = Uri.parse("android_secret_code://5201314");
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction() == null) {
log.i(TAG, "Null action");
return;
}
if (intent.getAction().equals(SECRET_CODE_ACTION)) {
Uri uri = intent.getData();
log.i(TAG, "getIntent success in if");
if (uri.equals(mLoveUri)) {
Intent intentLoveU = new Intent(context, LoveUActivity.class);
intentLoveU.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
log.i(TAG, "Before start LoveU activity");
context.startActivity(intentLoveU);
} else {
log.i(TAG, "No matched URI!");
}
} else {
log.i(TAG, "Not SECRET_CODE_ACTION!");
}
}
}
4. 定义Android工程App的XXXActivity,好戏从这里才刚刚开始哦!