private static AndroidJavaObject sHttpDnsObj;
public static void Init() {
AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
if (unityPlayerClass == null) {
return;
}
AndroidJavaObject activityObj = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
if (activityObj == null) {
return;
}
AndroidJavaObject contextObj = activityObj.Call<AndroidJavaObject>("getApplicationContext");
AndroidJavaObject httpDnsClass = new AndroidJavaObject("com.tencent.msdk.dns.MSDKDnsResolver");
if (httpDnsClass == null) {
return;
}
sHttpDnsObj = httpDnsClass.CallStatic<AndroidJavaObject>("getInstance");
if (sHttpDnsObj == null) {
return;
}
AndroidJavaObject dnsConfigBuilder = new AndroidJavaObject("com.tencent.msdk.dns.DnsConfig$Builder");
dnsConfigBuilder.Call<AndroidJavaObject>("dnsId", "XXX");
dnsConfigBuilder.Call<AndroidJavaObject>("dnsIp", "XXX");
dnsConfigBuilder.Call<AndroidJavaObject>("dnsKey", "XXX");
AndroidJavaObject dnsConfig = dnsConfigBuilder.Call<AndroidJavaObject>("build");
sHttpDnsObj.Call("init", contextObj, dnsConfig);
sHttpDnsObj.Call("init", contextObj, appkey, dnsid, dnskey, dnsIp, debug, timeout);
}
本页内容是否解决了您的问题?