Android 装逼技术之暗码启动应用

什么是暗码?
在拨号盘中输入*#*#<code>#*#*后,APP 可以监控到这些输入,然后做相应的动作,比如启动应用,是不是有点骚。
下面看下这个骚操作是如何实现的。
效果预览

源码
DialtactsActivity#showDialpadFragment
DialtactsActivity 中有个 showDialpadFragment 方法,用来加载显示拨号盘,因此入口就从 showDialpadFragment 看起,基于 Android P 分析。
private void showDialpadFragment(boolean animate) {
//……
final FragmentTransaction ft = getFragmentManager().beginTransaction();
if (dialpadFragment == null) {
dialpadFragment = new DialpadFragment();
ft.add(R.id.dialtacts_container, dialpadFragment, TAG_DIALPAD_FRAGMENT);
} else {
ft.show(dialpadFragment);
}
//……
}
具体实现在 DialpapFragment 中,看到 DialpapFragment 实现了 TextWatcher,TextWatcher 有 3 个重要方法,分别为:beforeTextChanged,onTextChanged 和 afterTextChanged,重点看 afterTextChanged 方法。
DialpadFragment#afterTextChanged
public class DialpadFragment extends Fragment
implements View.OnClickListener,
View.OnLongClickListener,
View.OnKeyListener,
AdapterView.OnItemClickListener,
TextWatcher,
PopupMenu.OnMenuItemClickListener,
DialpadKeyButton.OnPressedListener {
//……
@Override
public void afterTextChanged(Editable input) {
// When DTMF dialpad buttons are being pressed, we delay SpecialCharSequenceMgr sequence,
// since some of SpecialCharSequenceMgr's behavior is too abrupt for the "touch-down"
// behavior.
if (!digitsFilledByIntent
&& SpecialCharSequenceMgr.handleChars(getActivity(), input.toString(), digits)) {
// A special sequence was entered, clear the digits
digits.getText().clear();
}
if (isDigitsEmpty()) {
digitsFilledByIntent = false;
digits.setCursorVisible(false);
}
if (dialpadQueryListener != null) {
dialpadQueryListener.onDialpadQueryChanged(digits.getText().toString());
}
updateDeleteButtonEnabledState();
}
//……
}
这里调用了 SpecialCharSequenceMgr 辅助工具类的 handleChars 方法,看这个方法。
SpecialCharSequenceMgr#handleChars
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);
if (handleDeviceIdDisplay(context, dialString)
|| handleRegulatoryInfoDisplay(context, dialString)
|| handlePinEntry(context, dialString)
|| handleAdnEntry(context, dialString, textField)
|| handleSecretCode(context, dialString)) {
return true;
}
if (MotorolaUtils.handleSpecialCharSequence(context, input)) {
return true;
}
return false;
}
handleChars 方法中,会对各种特殊的 secret code 进行匹配处理,这里我们看 handleSecretCode。
SpecialCharSequenceMgr#handleSecretCode
static boolean handleSecretCode(Context context, String input) {
// Secret code specific to OEMs should be handled first.
if (TranssionUtils.isTranssionSecretCode(input)) {
TranssionUtils.handleTranssionSecretCode(context, input);
return true;
}
// Secret codes are accessed by dialing *#*#<code>#*#* or "*#<code_starting_with_number>#"
if (input.length() > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) {
String secretCode = input.substring(4, input.length() - 4);
TelephonyManagerCompat.handleSecretCode(context, secretCode);
return true;
}
return false;
}
再看下 TelephonyManagerCompat.handleSecretCode 方法。
TelephonyManagerCompat#handleSecretCode
public static void handleSecretCode(Context context, String secretCode) {
// Must use system service on O+ to avoid using broadcasts, which are not allowed on O+.
if (BuildCompat.isAtLeastO()) {
if (!TelecomUtil.isDefaultDialer(context)) {
LogUtil.e(
"TelephonyManagerCompat.handleSecretCode",
"not default dialer, cannot send special code");
return;
}
context.getSystemService(TelephonyManager.class).sendDialerSpecialCode(secretCode);
} else {
// System service call is not supported pre-O, so must use a broadcast for N-.
Intent intent =
new Intent(SECRET_CODE_ACTION, Uri.parse("android_secret_code://" + secretCode));
context.sendBroadcast(intent);
}
}
可以看到在拨号中接收到*#*#<code>#*#* 这样的指令时,程序会对外发送广播,这就意味着我们能够接收这个广播然后可以做我们想做的事情。
接下来我们看看这个接受广播代码是怎么写。
应用
首先在 AndroidManifest 文件中注册广播接收器。
<receiver
android:name=".SecretCodeReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code" android:host="1010" />
</intent-filter>
</receiver>
接收广播,启动应用。
public class SecretCodeReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && SECRET_CODE_ACTION.equals(intent.getAction())){
Intent i = new Intent(Intent.ACTION_MAIN);
i.setClass(context, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
}
这样只要在拨号中输入*#*#1010#*#*就能启动相应的应用程序,OK,收功。
公众号
我的公众号:吴小龙同学,欢迎关注交流~

Android 装逼技术之暗码启动应用的更多相关文章
- MTK Android 计算器Calculator输入暗码!77!+,启动工厂测试apk
Android8.0 计算器Calculator输入暗码!77!+,启动工厂测试apk 路径: packages/apps/ExactCalculator/src/com/android/calcul ...
- Android零基础入门第12节:熟悉Android Studio界面,开始装逼卖萌
原文:Android零基础入门第12节:熟悉Android Studio界面,开始装逼卖萌 通过前两期的学习,我们可以正确搭建好Android Studio的开发环境,也创建了HelloWorld工程 ...
- Android特效专辑(六)——仿QQ聊天撒花特效,无形装逼,最为致命
Android特效专辑(六)--仿QQ聊天撒花特效,无形装逼,最为致命 我的关于特效的专辑已经在CSDN上申请了一个专栏--http://blog.csdn.net/column/details/li ...
- 安卓工作室 Android studio 或 Intellij IDEA 美化 修改 汉化 酷炫 装逼 Android studio or Intellij IDEA beautify modify Chinesization cool decoration
安卓工作室 Android studio 或 Intellij IDEA 美化 修改 汉化 酷炫 装逼 Android studio or Intellij IDEA beautify modify ...
- WebApp简单制作(后端也可以装逼啦)
前端越来越吃香的感觉 年后回来,跟之前和几个同事和朋友聊天,发现有两个.net的和一个php的朋友都转到了前端,真是出乎意料.自从之前的webapp兴起后,前端感觉比后端吃香很多,总结朋友们转的原因, ...
- Android Small插件化框架源码分析
Android Small插件化框架源码分析 目录 概述 Small如何使用 插件加载流程 待改进的地方 一.概述 Small是一个写得非常简洁的插件化框架,工程源码位置:https://github ...
- 前端 JSer 装逼手册
阅读 8143收藏 2352016-7-18 SegmentFault 分享:吉祥物 @ SegmentFault 在装逼成本越来越高的 JS 圈,是时候充值一下了 -- 题记. 作者:kenberk ...
- 【转】Android 防破解技术简介
http://www.cnblogs.com/likeandroid/p/4888808.html Android 防破解技术简介 这几年随着互联网的不断发展,Android App 也越来越多!但是 ...
- 全面了解Android热修复技术
WeTest 导读 本文探讨了Android热修复技术的发展脉络,现状及其未来. 热修复技术概述 热修复技术在近年来飞速发展,尤其是在InstantRun方案推出之后,各种热修复技术竞相涌现.国内大部 ...
随机推荐
- mysql 优化 读写分离 主从复制
1:mysql所在服务器内核 优化 ---------此优化可由系统运维人员完成 2:mysql配置参数优化(my.cnf) -------- 此优化需进行压力测试来进行参数调整 3:sql语句及表 ...
- C# 特性的使用
using ClassLibrary;using System;using System.Collections.Generic;using System.Linq;using System.Refl ...
- Win8Metro(C#)数字图像处理--2.28图像乘法运算
原文:Win8Metro(C#)数字图像处理--2.28图像乘法运算 [函数名称] 图像乘法函数MultiplicationProcess(WriteableBitmap src, Writea ...
- 图像处理中的跨度(stride)
原文:图像处理中的跨度(stride) 使用C#的BitmapData 最近要转开发平台,正研究C#.C#好是好,不过处理图片时一个像素一个像素的操作像素不是一般的慢.其实Delphi也一样,但好在D ...
- C#程序以管理员的身份运行
在一些特定的情况下我们需要能够有管理员的权限,这样我们的很多执行,或者写入就不会报错了. 1.解决方案资源管理器---->项目(右键)--->属性-->安全性 2.勾选“启用Clic ...
- Win10《芒果TV》跨年邀你嗨唱,同步直播《湖南卫视2017-2018跨年演唱会》
由天天兄弟.快本家族联袂主持,不容错过的年度盛典<湖南卫视2017-2018跨年演唱会>将于2017年12月31日19:30起由芒果TV同步直播,果妈备上礼物邀您一起跨年嗨唱. 跨年邀你嗨 ...
- SqlServer 可更新订阅队列读取器代理错误:试图进行的插入或更新已失败
原文:SqlServer 可更新订阅队列读取器代理错误:试图进行的插入或更新已失败 今天发现队列读取器代理不停地尝试启动但总是出错: 其中内容如下: 队列读取器代理在连接"Publicati ...
- autotools工具使用 good
学习GNU/LINUX开发的编程人员,上手之后不久就会在编译开源软件的时候碰到configure脚本,过段时间还会知道configure脚本是 autoconf生成的:但是真正想用起来autoconf ...
- Postman调试中文出现乱码问题
最近在通过postman调试接口的时候,发现post的数据在中文的时候,传输到后台变成了问号(???),经过网上的资料与验证,找到了解决方案:在请求头中添加charset=UTF-8的属性,后续在进行 ...
- 【Linux】Linux 环境下splite以及一些正则使用
由于在windows下,遍历目录,想查找满足条件的文件: dir /s > ..\fileresult.txt 结果得到的文件过大,999多MB的txt: split -b 10k date.f ...