获取谷歌广告ID和广告限制 [英] Getting the Google Advertising ID and Limit Advertising
问题描述
我建立一个统一Android应用,并看一些广告。一个我们正在考虑的服务的要求我的谷歌广告的标识和广告的极限状态,为了做服务器到服务器转换跟踪。
I'm building a Unity Android app, and looking at some advertising. One of the services we are considering requires my google advertising ID and limit advertising state in order to do server-to-server conversion tracking.
问题是我不知道如何的团结让任何一个值。好像我需要某种形式的插件?我已经有谷歌广告服务的实施,并在使用AdMob和Chartboost,但尽可能接近我可以告诉这些都不插件,让我获得了Java调用,我需要找回前面提到的值。
The problem is I'm not sure how to get either of these values within Unity. It seems like I would need some form of plugin? I already have google ad services implemented and in use for both AdMob and Chartboost, but as near as I can tell neither of these plugins give me access to the java calls I would need to retrieve the aforementioned values.
所以我想我不知道如何访问我所需要的数据。我很犹豫,更多的插件加入到游戏中,因为他们得到足够的难以管理,因为它是。如果我理解正确的话,我认为应该有访问通过统一的图书馆Java的一种方式,但我没有丝毫如何做到这一点。
So I guess I'm not sure how to access the data I need. I'm hesitant to add more plugins to the game because they are getting difficult enough to manage as it is. If I understand correctly I think there should be a way to access the java through Unity's libraries, but I haven't the slightest how to do that.
推荐答案
我可以用下面的code,以获得所需的数据:
I was able to get the desired data using the following code:
string advertisingID = "";
bool limitAdvertising = false;
AndroidJavaClass up = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = up.GetStatic<AndroidJavaObject> ("currentActivity");
AndroidJavaClass client = new AndroidJavaClass ("com.google.android.gms.ads.identifier.AdvertisingIdClient");
AndroidJavaObject adInfo = client.CallStatic<AndroidJavaObject> ("getAdvertisingIdInfo",currentActivity);
advertisingID = adInfo.Call<string> ("getId").ToString();
limitTracking = (adInfo.Call<bool> ("isLimitAdTrackingEnabled"));
这篇关于获取谷歌广告ID和广告限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!