从代码Android设置的SECRET_CODE [英] SECRET_CODE set from code Android

查看:497
本文介绍了从代码Android设置的SECRET_CODE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用清单文件中的秘密代码,它可以很好地与以下源代码一起工作:

I know how to work with Secret code from Manifest file, it is working well with this source code:

 <receiver android:name="receivers.SecretCodeReceiver">
        <intent-filter>
            <action android:name="android.provider.Telephony.SECRET_CODE" />


            <data
                android:host="666"
                android:scheme="android_secret_code" />

        </intent-filter>
    </receiver>

但是,如何从源代码更改主机?可能吗 ?我尝试了这个:

But, how i can change host from source code ? Is it possible ? I tried this one:

sendBroadcast(new Intent("android.provider.Telephony.SECRET_CODE", Uri.parse("android_secret_code://"+code)));

但是没有运气。

推荐答案

修改Manifest.xml文件

Modify Manifest.xml file

<receiver android:name="receivers.SecretCodeReceiver">
  <intent-filter >
       <action android:name="android.provider.Telephony.SECRET_CODE" />
       <data android:scheme="android_secret_code" />
  </intent-filter>
</receiver>

并修改您的广播接收器类

And modify your Broadcast Receiver class

if(intent.getAction().equals("android.provider.Telephony.SECRET_CODE")) {
        String uri = intent.getDataString();
        String[] sep = uri.split("://");
        if (sep[1].equalsIgnoreCase("1234")) {
            Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("com.whatsapp");
            context.startActivity(launchIntent);
        } else if (sep[1].equalsIgnoreCase("5678")) {
            Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage("net.one97.paytm");
            context.startActivity(launchIntent);
        } 
    }

现在从Dialer *#*#NUMBER#*#* 例如。 *#*#1234#*#* 用于启动whatsapp

Now dial number from dialer*#*#NUMBER#*#* eg.*#*#1234#*#* for launch whatsapp

这篇关于从代码Android设置的SECRET_CODE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆