Android手机安全码编程知识
在android系统中,安全码就是类似这种样式的字符串: *#*##*#* 如果这样的系统安全码执行,系统会触发下面的方法:(来自 AOSP Android Open Source Project)
什么是安全码?
在android系统中,安全码就是类似这种样式的字符串: *#*#<code>#*#*
如果这样的系统安全码执行,系统会触发下面的方法:(来自 AOSP Android Open Source Project)
static private boolean handleSecretCode(Context context, String input) {
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;
}
如何运行安全码?
有两种方式可以执行运行安全码:
直接在手机电话拨号界面输入安全码,例如:*#*#123456789#*#*
或者直接在代码中进行调用。
String secretCode = "123456789";
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:*#*#" + secretCode + "#*#*"));
startActivity(intent);
String secretCode = "123456789";
String action = "android.provider.Telephony.SECRET_CODE";
Uri uri = Uri.parse("android_secret_code://" + secretCode);
Intent intent = new Intent(action, uri);
sendBroadcast(intent);
如何创建自定义安全码?
在你的应用AndroidManifest.xml文件中,增加以下代码,用来定义手机安全码。
不管什么时候安全码 *#*#123456789#*#* 被触发,你都将收到对应的广播。
<receiver android:name=".MySecretCodeReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<data android:scheme="android_secret_code" android:host="123456789" />
</intent-filter>
</receiver>
本文由 TecHug 分享,英文原文及文中图片来自 www.jianshu.com。
你也许感兴趣的:
- Android对美国外部内容链接引入2-4美元安装费及10-20%分成政策
- 对比安卓替代系统:Lineage OS、∕e∕OS 与 Graphene OS
- Rust在Android中的应用:内存安全漏洞密度较C/C++降低了1000倍
- 谷歌将允许用户在无需验证的情况下侧载(sideload)安卓应用
- F-Droid:我们要争取的侧载(sideload)究竟指什么
- 谷歌将于2026年合并安卓与ChromeOS,因人工智能
- 将桌面 Linux 图形界面引入 Android:图形应用支持的下一步
- 谷歌确认安卓开发者验证将设免费与付费层级,不再公开开发者名单
- 谷歌将要求开发者验证才能安装安卓应用,包括侧载安装
- 请准备好将 Android 应用的内存页大小过渡到 16 KB

你对本文的反应是: