我知道如何使用 list 文件中的 secret 代码,它与此源代码配合良好:
<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)));
但运气不佳。
最佳答案
修改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);
}
}
现在从拨号器调用号码*#*#NUMBER#*#*
例如*#*#1234#*#*
以启动whatsapp
关于android - 从 Android 代码设置的 SECRET_CODE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31647314/