暗码启动应用方式

暗码启动

  • packages/apps/Contacts/src/com/android/contacts/SpecialCharSequenceMgr.java
 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 >##* 这样的指令时,程序会对外发送广播。

拨号盘启动

注册广播

    <receiver android:name=".broadcast.PhoneBroadcastReceiver">
          <intent-filter>
              <action android:name="android.provider.Telephony.SECRET_CODE"/>
              <data
                  android:host="8888"
                  android:scheme="android_secret_code"/>
          </intent-filter>
      </receiver>

广播启动

public static final String SECRET_CODE_ACTION = "android.provider.Telephony.SECRET_CODE";

    @Override
    public void onReceive(Context context, Intent intent) {

        switch (intent.getAction()) {

            case SECRET_CODE_ACTION:
                 Uri uri = intent.getData();
                 if(uri != null){
                    String host = uri.getSchemeSpecificPart().substring(2);
        
                    if("8888".quals(host)){

                        //启动应用
                        Intent intent = new Intent(context, LoginActivity.class);
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        context.startActivity(i);
                    }
                }
            break;
        }

    }
}

通过代码发广播拉起暗码

系统权限

androi:sharedUserId="android.uid.system"

发送广播

Intent intent = new Intent("android.provider.Telephony.SECRET_CODE", Uri.parse("android_sercret_code://8888"));
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
this.sendBraodcast(tntent, null);

其他参考:你不知道的android黑科技:暗码启动应用程序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值