static RegisterService() { UnityEngine.AndroidJavaClass c = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer"); var context = c.GetStatic<UnityEngine.AndroidJavaObject>("currentActivity"); if (context == null) { c.Dispose(); throw new Exception("Failed to get context"); } var arg = new UnityEngine.AndroidJavaObject("java.lang.String", "servicediscovery"); context.Call<UnityEngine.AndroidJavaObject>("getSystemService", arg); context.Dispose(); arg.Dispose(); c.Dispose(); }
/// <summary> /// 连接华为推送并获取token,必须集成华为推送SDK /// </summary> public static void InitHuaweiPush() { using (var actClass = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer")) { UnityEngine.AndroidJavaObject curActivityContext = actClass.GetStatic <UnityEngine.AndroidJavaObject>("currentActivity"); if (curActivityContext != null) { UnityEngine.AndroidJavaClass clsSystemUtil = new UnityEngine.AndroidJavaClass("com.netease.hwpushwrapper.HWPush"); if (clsSystemUtil != null) { clsSystemUtil.CallStatic("initHuaweiPush", curActivityContext); UnityEngine.Debug.Log("call java method initHuaweiPush"); } else { UnityEngine.Debug.Log("can't find class com.netease.hwpushwrapper.HWPush"); } } } }
public static string GetAndroidExternalFilesDir() { using (UnityEngine.AndroidJavaClass unityPlayer = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer")) { using (UnityEngine.AndroidJavaObject context = unityPlayer.GetStatic <UnityEngine.AndroidJavaObject>("currentActivity")) { // Get all available external file directories (emulated and sdCards) UnityEngine.AndroidJavaObject[] externalFilesDirectories = context.Call <UnityEngine.AndroidJavaObject[]>("getExternalFilesDirs", (object)null); UnityEngine.AndroidJavaObject emulated = null; UnityEngine.AndroidJavaObject sdCard = null; for (int i = 0; i < externalFilesDirectories.Length; i++) { UnityEngine.AndroidJavaObject directory = externalFilesDirectories[i]; using (UnityEngine.AndroidJavaClass environment = new UnityEngine.AndroidJavaClass("android.os.Environment")) { // Check which one is the emulated and which the sdCard. bool isRemovable = environment.CallStatic <bool>("isExternalStorageRemovable", directory); bool isEmulated = environment.CallStatic <bool>("isExternalStorageEmulated", directory); if (isEmulated) { emulated = directory; } else if (isRemovable && isEmulated == false) { sdCard = directory; } } } // Return the sdCard if available if (sdCard != null) { return(sdCard.Call <string>("getAbsolutePath")); } else { return(emulated.Call <string>("getAbsolutePath")); } } } }
static RegisterService() { Couchbase.Lite.Unity.UnityMainThreadScheduler.TaskFactory.StartNew(() => { UnityEngine.AndroidJavaClass c = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer"); var context = c.GetStatic <UnityEngine.AndroidJavaObject>("currentActivity"); if (context == null) { c.Dispose(); throw new Exception("Failed to get context"); } var arg = new UnityEngine.AndroidJavaObject("java.lang.String", "servicediscovery"); context.Call <UnityEngine.AndroidJavaObject>("getSystemService", arg); context.Dispose(); arg.Dispose(); c.Dispose(); _primedEvent.Set(); }); }
private static void InitSystemUtil() { #if UNITY_ANDROID try { /* The Mono garbage collector should release all created instances of AndroidJavaObject and AndroidJavaClass after use, * but it is advisable to keep them in a using(){} statement to ensure they are deleted as soon as possible. * Without this, you cannot be sure when they will be destroyed. */ using (var actClass = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer")) { UnityEngine.AndroidJavaObject curActivityContext = actClass.GetStatic <UnityEngine.AndroidJavaObject>("currentActivity"); if (curActivityContext != null) { UnityEngine.AndroidJavaClass clsSystemUtil = new UnityEngine.AndroidJavaClass("com.netease.nimlib.NIMSDK"); if (clsSystemUtil != null) { NimUtility.Log.Info("com.netease.nimlib.NIMSDK found"); Boolean init = clsSystemUtil.CallStatic <Boolean>("init", curActivityContext, "fjni_wrapper"); NimUtility.Log.Info("init:" + init); //string androidId = clsSystemUtil.CallStatic<String>("getAndroidId"); //NimUtility.Log.Info("androidId:" + androidId); } } } } catch (System.Exception e) { System.Console.Write("initAndroidExceptionHandler failed, an unexpected error: " + e.ToString()); } #endif #if UNITY_IPHONE || UNITY_IOS if (UnityEngine.Application.platform == UnityEngine.RuntimePlatform.IPhonePlayer) { //TODO: } #endif }
/** 終了。 */ public static void End(Root_MonoBehaviour a_root_monobehaviour) { if (a_root_monobehaviour.loadandroidcontentfile != null) { try{ using (UnityEngine.AndroidJavaClass t_class_loadcontentfile = new UnityEngine.AndroidJavaClass("fee.platform.Android_LoadAndroidContentFile_AsyncObject")){ t_class_loadcontentfile.CallStatic("End", a_root_monobehaviour.loadandroidcontentfile); } }catch (System.Exception t_exception) { Tool.DebugReThrow(t_exception); } } if (a_root_monobehaviour.loadandroidcontentfile != null) { try{ a_root_monobehaviour.loadandroidcontentfile.Dispose(); }catch (System.Exception t_exception) { Tool.DebugReThrow(t_exception); } a_root_monobehaviour.loadandroidcontentfile = null; } }
/** 開始。 */ public static bool Start(Root_MonoBehaviour a_root_monobehaviour, Fee.File.Path a_path) { if (a_root_monobehaviour.loadandroidcontentfile == null) { UnityEngine.AndroidJavaObject t_async_object = null; try{ using (UnityEngine.AndroidJavaClass t_class_loadcontentfile = new UnityEngine.AndroidJavaClass("fee.platform.Android_LoadAndroidContentFile_AsyncObject")){ t_async_object = t_class_loadcontentfile.CallStatic <UnityEngine.AndroidJavaObject>("Start", a_path.GetPath()); } }catch (System.Exception t_exception) { Tool.DebugReThrow(t_exception); } if (t_async_object != null) { a_root_monobehaviour.loadandroidcontentfile = t_async_object; return(true); } } return(false); }
/** GetResult。 */ public static byte[] GetResult(Root_MonoBehaviour a_root_monobehaviour) { byte[] t_ret = null; if (a_root_monobehaviour.loadandroidcontentfile != null) { try{ using (UnityEngine.AndroidJavaClass t_class_loadcontentfile = new UnityEngine.AndroidJavaClass("fee.platform.Android_LoadAndroidContentFile_AsyncObject")){ using (UnityEngine.AndroidJavaObject t_array_object = t_class_loadcontentfile.CallStatic <UnityEngine.AndroidJavaObject>("GetResult", a_root_monobehaviour.loadandroidcontentfile)){ if (t_array_object != null) { System.IntPtr t_array_object_pointer = t_array_object.GetRawObject(); t_ret = UnityEngine.AndroidJNIHelper.ConvertFromJNIArray <byte[]>(t_array_object_pointer); } } } }catch (System.Exception t_exception) { Tool.DebugReThrow(t_exception); t_ret = null; } } return(t_ret); }
static ServiceBrowser() { Couchbase.Lite.Unity.UnityMainThreadScheduler.TaskFactory.StartNew(() => { UnityEngine.AndroidJavaClass c = new UnityEngine.AndroidJavaClass("com.unity3d.player.UnityPlayer"); var context = c.GetStatic<UnityEngine.AndroidJavaObject>("currentActivity"); if (context == null) { c.Dispose(); throw new Exception("Failed to get context"); } var arg = new UnityEngine.AndroidJavaObject("java.lang.String", "servicediscovery"); context.Call<UnityEngine.AndroidJavaObject>("getSystemService", arg); context.Dispose(); arg.Dispose(); c.Dispose(); _primedEvent.Set(); }); }
static SimpleClass() { _javaClass = new UnityEngine.AndroidJavaClass("unity_aanp.testjar.SimpleClass"); }