android中实现暗码启动apk【一】
16lz
2021-01-26
相信大家一定接触过手机里面的各种暗码启动app,最熟悉的就是在拨号盘输入”*#06#” 查看手机的IMEI号。
如果我们也想实现一样的功能,自定义暗码启动我们自己的app,该如何实现呢,其实去网上搜索暗码启动apk,有很多相关的栗子,也说的很清楚,我在此记录下我实现此功能的方法。
我实现此功能是在MTK平台上实现的。所以是直接把代码加到源码中编译。
直接贴代码:
SecretSwupReceiver.java
import android.content.ActivityNotFoundException;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.net.Uri;import android.util.Log;public class SecretSwupReceiver extends BroadcastReceiver{ public static String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE"; private final Uri mSwupUri= Uri.parse("android_secret_code://666666"); private static final String TAG = "SecretSwupReceiver"; @Override public void onReceive(Context context, Intent intent) { if (intent.getAction() == null) { Log.i(TAG, "Null action"); return; } if (intent.getAction().equals(SECRET_CODE_ACTION)) { Uri uri = intent.getData(); Log.i(TAG, "getIntent success in if"); if (uri.equals(mSwupUri)) { ***Intent mIntent = new Intent(context, MainActivity.class);*** mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { context.startActivity(mIntent); } catch (ActivityNotFoundException e) { Log.i(TAG, "startActivity() failed:"+e); } } } }}
AndroidMainfest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.testbg" android:versionCode="1" android:versionName="1.0" > <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-feature android:name="android.hardware.usb.host" /> <uses-permission android:name="android.permission.USB_PERMISSION" /> <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.***DEFAULT***" /> intent-filter> activity> ***<receiver android:name=".SecretSwupReceiver" android:exported="true" > <intent-filter> <action android:name="android.provider.Telephony.SECRET_CODE" /> <data android:host="666666" android:scheme="android_secret_code" /> intent-filter> receiver>*** application>manifest>
我只贴了
SecretSwupReceiver.java 和AndroidMainfest.xml的代码,因为关键代码就这两个文件,其他的就不贴了。注意文中加粗红色标注的地方。LAUNCHER需要改成
DEFAULT这样可以隐藏图标。
代码写好了就直接编译一下,编译成功后,在拨号盘输入你自定义的暗码,我定义的“666666”,输入“*#*#666666#*#*”就可以启动apk了。
更多详细内容可参考博客:http://blog.csdn.net/easy_gemini/article/details/8230869
http://blog.csdn.net/qq3162380/article/details/45393335
更多相关文章
- Android(安卓)Studio错误代码不提示问题解决
- android eclipse 混淆jar代码
- 「「第一行代码(第二版)」」学习笔记 6 广播机制(连载中)
- Android(安卓)选择联系人+返回对应手机号码
- 浅析Android中强大的Dialog
- Android应用程序权限机制的源代码分析(1)
- 利用WCF与Android实现图片上传并传参
- android官方最新以及2.2、2.3.5源代码(完整)下载以及用source insi
- 在eclipse中导入android4.0中的Launcher2并且编译运行