手机拨号启动隐藏程序
16lz
2021-01-26
最近做一个出厂测试的程序,因为不能直接显示到程序列表中,因此需要将程序隐藏,再通过拨打*#*#xxxx#*#*来启动程序。在这里和大家分享分享。
一.先看看Android源码 (笔者参考的是Android2.3)。
联系人模块中有一个文件 packages/apps/Contacts/src/com/android/contacts/SpecialCharSequenceMgr.java,相关代码段为
/** * Handles secret codes to launch arbitrary activities in the form of *#*#<code>#*#*. * If a secret code is encountered an Intent is started with the android_secret_code://<code> * URI. * * @param context the context to use * @param input the text to check for a secret code in * @return true if a secret code was encountered */ static boolean handleSecretCode(Context context, String input) { // Secret codes are in the form *#*#<code>#*#* int len = input.length(); if (len > 8 && input.startsWith("*#*#") && input.endsWith("#*#*")) { Intent intent = new Intent(Intents.SECRET_CODE_ACTION, Uri.parse("android_secret_code://" + input.substring(4, len - 4))); context.sendBroadcast(intent); return true; } return false; }这里,在拨号中已经做了处理,当收到 *#*#<code>#*#* 时,程序会发送广播,那么我们只需要接收这个广播再去做相应处理就OK了。
二.定义相应的广播接收器。
package com.xxx.ftest;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.net.Uri;public class SecretLaunchReceiver extends BroadcastReceiver {public static final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE";/** * the uri is like : android_secret_code://1234 */@Overridepublic void onReceive(final Context context, Intent intent) {if (intent.getAction().equals(SECRET_CODE_ACTION)) {Uri uri = intent.getData();System.out.println("SecretLaunchReceiver onReceive: " + uri);if(uri != null){String content = uri.getSchemeSpecificPart().substring(2);if("0755".equals(content)){Intent i = new Intent(context, ModeChooserActivity.class);i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);context.startActivity(i);}}}}}
三.在自己程序的Manifest文件中,注册广播接收器。
<receiver android:name="com.xxx.ftest.SecretLaunchReceiver" > <intent-filter> <action android:name="android.provider.Telephony.SECRET_CODE" /> <data android:scheme="android_secret_code" /> </intent-filter></receiver>
OK,打完收工,这样只要在拨号中输入 *#*#0755#*#*就可以启动自己的程序了。
原文地址:http://blog.csdn.net/ville_zeng/article/details/19496569, 欢迎转载!
更多相关文章
- android service 广播 更新 activity
- Android(安卓)查看动态库依赖的库文件
- Android程序检测网络是否可用
- Android源码中常用的系统广播
- 如何更改Android(安卓)程序的icon快捷方式图标?
- android 笔记 --- Intent 应用
- 在程序开发中必须了解Activity的四种启动模式
- android如何添加桌面图标和卸载程序后自动删除图标
- Android功耗相关信息收集