android中实现暗码启动apk【一】
2017-02-15 15:49
851 查看
相信大家一定接触过手机里面的各种暗码启动app,最熟悉的就是在拨号盘输入”*#06#” 查看手机的IMEI号。
如果我们也想实现一样的功能,自定义暗码启动我们自己的app,该如何实现呢,其实去网上搜索暗码启动apk,有很多相关的栗子,也说的很清楚,我在此记录下我实现此功能的方法。
我实现此功能是在MTK平台上实现的。所以是直接把代码加到源码中编译。
直接贴代码:
SecretSwupReceiver.java
AndroidMainfest.xml
我只贴了
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
如果我们也想实现一样的功能,自定义暗码启动我们自己的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
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件