AI手机网,短视频直播 硬改改机 一键新机 群控软件 刷机定制

 找回密码
 立即注册
搜索
查看: 1640|回复: 5

Android手机暗码浅谈

[复制链接]
发表于 2020-9-17 17:36:12 | 显示全部楼层 |阅读模式
在拨号盘中输入*#*#<code>#*#*以后, App可以监控到这些输入, 然后做相应的动作, 是不是很cool~
下面介绍一下这个小技巧.
什么是暗码?在android系统中,暗码就是类似这种样式的字符串: *#*#<code>#*#*   
如果这样的系统暗码执行,系统会触发下面的方法:(来自 AOSP Android Open Source Project)




  1. static private boolean handleSecretCode(Context context, String input) {
  2.     int len = input.length();
  3.     if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) {
  4.         Intent intent = new Intent(TelephonyIntents.SECRET_CODE_ACTION,
  5.                 Uri.parse("android_secret_code://" + input.substring(4, len - 4)));
  6.         context.sendBroadcast(intent);
  7.         return true;
  8.     }
  9.     return false;
  10. }
复制代码
如何运行暗码?
有两种方式可以执行运行暗码:
直接在手机电话拨号界面输入暗码,例如:*#*#123456789#*#*
或者直接在代码中进行调用。
  1. String secretCode = "123456789";
  2. Intent intent = new Intent(Intent.ACTION_DIAL);   
  3. intent.setData(Uri.parse("tel:*#*#" + secretCode + "#*#*"));
  4. startActivity(intent);  
复制代码
  1. String secretCode = "123456789";
  2. String action = "android.provider.Telephony.SECRET_CODE";
  3. Uri uri = Uri.parse("android_secret_code://" + secretCode);
  4. Intent intent = new Intent(action, uri);
  5. sendBroadcast(intent);
复制代码

如何创建自定义暗码?
在你的应用AndroidManifest.xml文件中,增加以下代码,用来定义手机暗码。
不管什么时候暗码 *#*#123456789#*#* 被触发,你都将收到对应的广播
  1. <receiver android:name=".MySecretCodeReceiver">
  2.     <intent-filter>
  3.         <action android:name="android.provider.Telephony.SECRET_CODE" />
  4.         <data android:scheme="android_secret_code" android:host="123456789" />
  5.     </intent-filter>
  6. </receiver>  
复制代码




发表于 2020-9-17 17:38:57 | 显示全部楼层
顶一下
发表于 2020-9-17 17:41:42 | 显示全部楼层
感谢客服指导
发表于 2020-9-17 17:44:24 | 显示全部楼层
不错!
发表于 2020-9-17 17:47:16 | 显示全部楼层
太棒了
发表于 2020-9-17 17:49:52 | 显示全部楼层
感谢刷机成功
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

技术交流售后群

QQ|小黑屋|手机版|站点找错-建议|AI手机网 |Sitemap



GMT+8, 2024-5-10 03:10 , Processed in 0.150896 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表