SECRET_CODE set from code Android

你离开我真会死。 提交于 2019-12-10 18:34:51

问题


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

But no luck.


回答1:


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);
        } 
    }

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



来源:https://stackoverflow.com/questions/31647314/secret-code-set-from-code-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!