void Start() { // Attach our thread to the java vm; obviously the main thread is already attached but this is good practice.. JavaVM.AttachCurrentThread(); // Enable logging for debugging. AndroidJavaClass tapjoyLog = new AndroidJavaClass("com.tapjoy.TapjoyLog"); tapjoyLog.CallStatic("enableLogging", true); // Get the activity context for Android. AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); currentActivity = jc.GetStatic <AndroidJavaObject>("currentActivity"); // Connect to the Tapjoy servers. tapjoyConnect = new AndroidJavaClass("com.tapjoy.TapjoyConnect"); tapjoyConnect.CallStatic("requestTapjoyConnect", currentActivity, // Activity context. "acd01aa3-04f3-4a40-bae5-21affbf9bf86", // YOUR APP ID GOES HERE "cQWKWp5HgYZuKGZQLAa0"); // YOUR SECRET KEY GOES HERE tapjoyConnectInstance = tapjoyConnect.CallStatic <AndroidJavaObject>("getTapjoyConnectInstance"); tapjoyConnectInstance.Call("initVideoAd"); }
public static void setPlacementId(String pid) { //This function will be used to change the gameObjectName. //In our sample project, Gameobject is "Main Camera" which has script "CallAirpush.cs" and it contain all callback listeners. //You need to set the name of game object which contains all callback listeners // again, make sure the thread is attached.. JavaVM.AttachCurrentThread(); // first we try to find our main activity.. IntPtr cls_Activity = JNI.FindClass("com/unity3d/player/UnityPlayer"); int fid_Activity = JNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;"); obj_Activity = JNI.GetStaticObjectField(cls_Activity, fid_Activity); // create a JavaClass object... IntPtr cls_JavaClass = JNI.FindClass("com/airpush/unity/MainActivity"); int mid_JavaClass = JNI.GetMethodID(cls_JavaClass, "<init>", "(Landroid/app/Activity;)V"); IntPtr obj_JavaClass = JNI.NewObject(cls_JavaClass, mid_JavaClass, obj_Activity); // create a global reference to the JavaClass object and fetch method id(s).. JavaClass = JNI.NewGlobalRef(obj_JavaClass); BtnMyAppWall = JNI.GetMethodID(cls_JavaClass, "setPlacementId", "(Ljava/lang/String;)V"); JNI.CallObjectMethod(JavaClass, BtnMyAppWall, JNI.NewStringUTF(pid)); }
void Start() { // attach our thread to the java vm; obviously the main thread is already attached but this is good practice.. JavaVM.AttachCurrentThread(); // first we try to find our main activity.. IntPtr cls_Activity = JNI.FindClass("com/unity3d/player/UnityPlayer"); int fid_Activity = JNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;"); IntPtr obj_Activity = JNI.GetStaticObjectField(cls_Activity, fid_Activity); Debug.Log("obj_Activity = " + obj_Activity); // create a JavaClass object... IntPtr cls_JavaClass = JNI.FindClass("org/example/ScriptBridge/JavaClass"); int mid_JavaClass = JNI.GetMethodID(cls_JavaClass, "<init>", "(Landroid/app/Activity;)V"); IntPtr obj_JavaClass = JNI.NewObject(cls_JavaClass, mid_JavaClass, obj_Activity); Debug.Log("JavaClass object = " + obj_JavaClass); // create a global reference to the JavaClass object and fetch method id(s).. JavaClass = JNI.NewGlobalRef(obj_JavaClass); getActivityCacheDir = JNI.GetMethodID(cls_JavaClass, "getActivityCacheDir", "()Ljava/lang/String;"); Debug.Log("JavaClass global ref = " + JavaClass); Debug.Log("JavaClass method id = " + getActivityCacheDir); }
public static void startAirBannerAdBottom() { // again, make sure the thread is attached.. JavaVM.AttachCurrentThread(); // first we try to find our main activity.. IntPtr cls_Activity = JNI.FindClass("com/unity3d/player/UnityPlayer"); int fid_Activity = JNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;"); obj_Activity = JNI.GetStaticObjectField(cls_Activity, fid_Activity); // create a JavaClass object... IntPtr cls_JavaClass = JNI.FindClass("com/airpush/unity/MainActivity"); int mid_JavaClass = JNI.GetMethodID(cls_JavaClass, "<init>", "(Landroid/app/Activity;)V"); IntPtr obj_JavaClass = JNI.NewObject(cls_JavaClass, mid_JavaClass, obj_Activity); JavaClass = JNI.NewGlobalRef(obj_JavaClass); BtnMyAppWall = JNI.GetMethodID(cls_JavaClass, "airBannerAdBottom", "()V"); // get the Java String object from the JavaClass object JNI.CallObjectMethod(JavaClass, BtnMyAppWall, JNI.NewStringUTF("top")); }
private bool InitalizeAndroidSoundBankIO() { JavaVM.AttachCurrentThread(); // Find main activity.. IntPtr cls_Activity = JNI.FindClass("com/unity3d/player/UnityPlayer"); int fid_Activity = JNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;"); IntPtr obj_Activity = JNI.GetStaticObjectField(cls_Activity, fid_Activity); if (obj_Activity == IntPtr.Zero) { Debug.LogError("WwiseUnity: Failed to get UnityPlayer activity. Abort."); return(false); } // Create a JavaClass object... const string AkPackageClass = "com/audiokinetic/aksoundengine/SoundBankIOInitalizerJavaClass"; IntPtr cls_JavaClass = JNI.FindClass(AkPackageClass); if (cls_JavaClass == IntPtr.Zero) { Debug.LogError("WwiseUnity: Failed to find Java class. Check if plugin JAR file is available in Assets/Plugins/Android. Abort."); return(false); } int mid_JavaClass = JNI.GetMethodID(cls_JavaClass, "<init>", "(Landroid/app/Activity;)V"); IntPtr obj_JavaClass = JNI.NewObject(cls_JavaClass, mid_JavaClass, obj_Activity); // Create a global reference to the JavaClass object and fetch method id(s).. IntPtr soundBankIOInitalizerJavaClass = JNI.NewGlobalRef(obj_JavaClass); int setAssetManagerMethodID = JNI.GetMethodID(cls_JavaClass, "SetAssetManager", "()I"); if (setAssetManagerMethodID == 0) { Debug.LogError("WwiseUnity: Failed to find Java class method. Check method name and signature in JNI query. Abort."); return(false); } // get the Java String object from the JavaClass object IntPtr ret = JNI.CallObjectMethod(soundBankIOInitalizerJavaClass, setAssetManagerMethodID); if (ret != IntPtr.Zero) { Debug.LogError("WwiseUnity: Failed to set AssetManager for Android SoundBank low-level IO handler."); return(false); } return(true); }
protected override void Login(string facebookAppID) { JavaVM.AttachCurrentThread(); //Find current Activity IntPtr clsActivity = JNI.FindClass("com/unity3d/player/UnityPlayer"); IntPtr objActivity = JNI.GetStaticObjectField(clsActivity, JNI.GetStaticFieldID(clsActivity, "currentActivity", "Landroid/app/Activity;")); //Create LoginAdapter obj IntPtr clsLAdapter = JNI.FindClass("com/socialnetwork/LoginAdapter"); IntPtr objlAdapter = JNI.NewObject(clsLAdapter, JNI.GetMethodID(clsLAdapter, "<init>", "(Landroid/app/Activity;)V"), objActivity); IntPtr lAdapter = JNI.NewGlobalRef(objlAdapter); if (JNI.CallBooleanMethod(lAdapter, JNI.GetMethodID(clsLAdapter, "Login", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z"), JNI.NewStringUTF(facebookAppID), JNI.NewStringUTF(host), JNI.NewStringUTF(port.ToString()), JNI.NewStringUTF("fb")) == 0) { return; } socketServer = new SocketServer(port); socketServer.ReadString += OnLoginEnded; }
public static void startAirIconAd() { JavaVM.AttachCurrentThread(); // first we try to find our main activity.. IntPtr cls_Activity = JNI.FindClass("com/unity3d/player/UnityPlayer"); int fid_Activity = JNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;"); obj_Activity = JNI.GetStaticObjectField(cls_Activity, fid_Activity); IntPtr cls_JavaClass = JNI.FindClass("com/airpush/unity/MainActivity"); int mid_JavaClass = JNI.GetMethodID(cls_JavaClass, "<init>", "(Landroid/app/Activity;)V"); IntPtr obj_JavaClass = JNI.NewObject(cls_JavaClass, mid_JavaClass, obj_Activity); JavaClass = JNI.NewGlobalRef(obj_JavaClass); BtnMyIcon = JNI.GetMethodID(cls_JavaClass, "airiconAd", "()V"); Debug.Log("parul6"); // get the Java String object from the JavaClass object JNI.CallObjectMethod(JavaClass, BtnMyIcon, JNI.NewStringUTF("Caching")); }
private string getCacheDir() { // again, make sure the thread is attached.. JavaVM.AttachCurrentThread(); // get the Java String object from the JavaClass object IntPtr str_cacheDir = JNI.CallObjectMethod(JavaClass, getActivityCacheDir); Debug.Log("str_cacheDir = " + str_cacheDir); // convert the Java String into a Mono string IntPtr stringPtr = JNI.GetStringUTFChars(str_cacheDir, 0); Debug.Log("stringPtr = " + stringPtr); String cache = Marshal.PtrToStringAnsi(stringPtr); JNI.ReleaseStringUTFChars(str_cacheDir, stringPtr); Debug.Log("return value is = " + cache); return(cache); }
// Use this for initialization public static void startAirSmartWallAd() { // This method can be directly called to show the smartwall ad directly without caching. // again, make sure the thread is attached.. JavaVM.AttachCurrentThread(); // first we try to find our main activity.. IntPtr cls_Activity = JNI.FindClass("com/unity3d/player/UnityPlayer"); int fid_Activity = JNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;"); obj_Activity = JNI.GetStaticObjectField(cls_Activity, fid_Activity); IntPtr cls_JavaClass = JNI.FindClass("com/airpush/unity/MainActivity"); int mid_JavaClass = JNI.GetMethodID(cls_JavaClass, "<init>", "(Landroid/app/Activity;)V"); IntPtr obj_JavaClass = JNI.NewObject(cls_JavaClass, mid_JavaClass, obj_Activity); JavaClass = JNI.NewGlobalRef(obj_JavaClass); BtnMySmart = JNI.GetMethodID(cls_JavaClass, "airSmartWallAd", "()V"); // get the Java String object from the JavaClass object JNI.CallObjectMethod(JavaClass, BtnMySmart, JNI.NewStringUTF("Caching")); }
// Use this for initialization public static void showCachedAirSmartWallAd() { // This method will be used to show the ad which has been cached by cacheAirSmartWallAd //This method will be used in conjunction with cacheAirSmartWallAd and should be called only after cacheAirSmartWallAd // again, make sure the thread is attached.. JavaVM.AttachCurrentThread(); // first we try to find our main activity.. IntPtr cls_Activity = JNI.FindClass("com/unity3d/player/UnityPlayer"); int fid_Activity = JNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;"); obj_Activity = JNI.GetStaticObjectField(cls_Activity, fid_Activity); IntPtr cls_JavaClass = JNI.FindClass("com/airpush/unity/MainActivity"); int mid_JavaClass = JNI.GetMethodID(cls_JavaClass, "<init>", "(Landroid/app/Activity;)V"); IntPtr obj_JavaClass = JNI.NewObject(cls_JavaClass, mid_JavaClass, obj_Activity); JavaClass = JNI.NewGlobalRef(obj_JavaClass); BtnMySmart = JNI.GetMethodID(cls_JavaClass, "airShowCachedAd", "()V"); // get the Java String object from the JavaClass object JNI.CallObjectMethod(JavaClass, BtnMySmart, JNI.NewStringUTF("Cached")); }