Hello,
I wrote my own simple plugin that returns a method. The package name is the same as my bundle identifier.
I have confirmed that it is in my .jar file. It also resides in Plugins/Android
MUST I also create a custom AndroidManifest.xml? The android class does not extend any unity activities. It’s a simple class.
Am I missing any important steps? I’ve wasted 6 hours on this already.
.cs
using(AndroidJavaClass activityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
AndroidJavaObject activityContext = activityClass.GetStatic<AndroidJavaObject>("currentActivity");
using(AndroidJavaObject pluginClass = new AndroidJavaObject("com.unlockable.adtracking.UnlockableAdTracking"))
{
if(pluginClass != null)
{
pluginClass.CallStatic("setContext", activityContext);
result = pluginClass.CallStatic<bool>("adTrackingEnabled");
}
}
}
Java:
package com.unlockable.adtracking;
import android.content.Context;
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
import com.google.android.gms.ads.identifier.AdvertisingIdClient.Info;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import java.io.IOException;
public class UnlockableAdTracking
{
private static Context context;
public static void setContext( Context ctxt )
{
context = ctxt;
}
public static Boolean adTrackingEnabled() throws IllegalStateException, GooglePlayServicesRepairableException
{
Info adInfo = null;
try
{
adInfo = AdvertisingIdClient.getAdvertisingIdInfo( context );
}
catch (IOException e)
{
//Unrecoverable error connecting to Google Play services (e.g.,
//the old version of the service doesn't support getting AdvertisingId).
}
catch (GooglePlayServicesNotAvailableException e)
{
// Google Play services is not available entirely.
}
return adInfo.isLimitAdTrackingEnabled();
}
}