【问题标题】:SECRET_CODE set from code Android从代码 Android 设置的 SECRET_CODE
【发布时间】:2015-07-27 07:34:05
【问题描述】:

我知道如何使用 Manifest 文件中的秘密代码,它与此源代码配合得很好:

 <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>

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

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

但没有运气。

【问题讨论】:

    标签: android broadcast


    【解决方案1】:

    修改 Manifest.xml 文件

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

    并修改您的广播接收器类

    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

    【讨论】:

    • 此代码在我的 MI4i 设备上不起作用。 BroadcastReceiver 似乎从未注册过。你能帮帮我吗?
    • 我在 HTC One S 或 Galaxy S6 上也是如此。输入代码后,BroadcastReceiver 永远不会被调用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 2012-02-24
    • 1970-01-01
    相关资源
    最近更新 更多