手机拨号启动隐藏程序 您所在的位置:网站首页 华为10怎么隐藏应用程序软件 手机拨号启动隐藏程序

手机拨号启动隐藏程序

2024-07-07 12:02| 来源: 网络整理| 查看: 265

       最近做一个出厂测试的程序,因为不能直接显示到程序列表中,因此需要将程序隐藏,再通过拨打*#*#xxxx#*#*来启动程序。在这里和大家分享分享。

一.先看看Android源码 (笔者参考的是Android2.3)。         联系人模块中有一个文件 packages/apps/Contacts/src/com/android/contacts/SpecialCharSequenceMgr.java,相关代码段为

/** * Handles secret codes to launch arbitrary activities in the form of *#*##*#*. * If a secret code is encountered an Intent is started with the android_secret_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 *#*##*#* 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; }        这里,在拨号中已经做了处理,当收到 *#*##*#* 时,程序会发送广播,那么我们只需要接收这个广播再去做相应处理就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 */ @Override public 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文件中,注册广播接收器。

        OK,打完收工,这样只要在拨号中输入 *#*#0755#*#*就可以启动自己的程序了。

原文地址:http://blog.csdn.net/ville_zeng/article/details/19496569, 欢迎转载!



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有