当前位置:   article > 正文

android 拨号启动秘密app 无界面 receiver_拨号进入rece

拨号进入rece
至少在API=8,android还是支持无界面app的,比如一个app只有一个receiver,实现特定的功能;但到至多android 4.0已经默认不支持这样只有一个receiver的app了,即app必须具有activity,至于系统内置的无activity的app如何配置的,我还不清楚,但大部分情况下,android应该不允许无activity视图的app的receiver运行的,像接下来要介绍的秘密app(通常用于工厂指令调试),在android 4.0及以上平台是无法工作的;这类外部app用户通常看不到入口图标,就有可能成为病毒app之类的,为了安全,还是需要一个activity让用户看看的。
刚发现在<receiver>中添加<category android:name="android.intent.category.HOME" />可以在高版本API,实现无界面(activity)启动receiver
如:
  1. <receiver
  2. android:name=".AlarmReceiver"
  3. android:exported="false" >
  4. <intent-filter>
  5. <action android:name="android.alarm.action.send" />
  6. <action android:name="android.intent.action.BOOT_COMPLETED" />
  7. <action android:name="android.intent.action.TIME_SET" />
  8. <category android:name="android.intent.category.HOME" />
  9. </intent-filter>
  10. </receiver>
言归正传,仅以下代码生成的app在android 4.0无法工作,app需要至少一个activity,或者如上添加   <category  >,而在android2.2可以工作。

1.声明在menifest.xml里面声明receiver:
  1. <receiver android:name=".startSettings">
  2. <intent-filter>
  3. <action android:name="android.provider.Telephony.SECRET_CODE" />
  4. <data android:host="0556" android:scheme="android_secret_code" />
  5. <data android:host="0557" android:scheme="android_secret_code" /> //可以有多个data
  6. </intent-filter>
  7. </receiver>

2.java 代码
  1. public class startSettings extends BroadcastReceiver {
  2. @Override
  3. public void onReceive(Context context, Intent intent) {
  4. String host;
  5. if (intent.getData() != null) {
  6. host = intent.getData().getHost();
  7. } else return;
  8. if (host.equals("0556")) {
  9. //TODO,启动一个程序,如下启动RootExplorer
  10. Intent it = new Intent("android.intent.action.MAIN");
  11. it.setClassName("com.speedsoftware.rootexplorer","com.speedsoftware.rootexplorer.RootExplorer");
  12. context.startActivity(it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));//必须要FLAG_ACTIVITY_NEW_TASK
  13. } else {
  14. //TODO
  15. }
  16. }
  17. }

3.键盘拨号启动:*#*#0557#*#*  , 0556就是menifest.xml里面的 android:host="0556"

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/308485?site=
推荐阅读
相关标签
  

闽ICP备14008679号