Exemplo n.º 1
0
 public string UpdateMemoryInfo()
 {
     memsize        = androidJavaObject.CallStatic <long>("getUsedMemorySize");
     maxsize        = androidJavaObject.CallStatic <long>("totalMemorySize");
     currentMemInfo = memsize / 1024 + "MB/" + maxsize / 1024 / 1024 + "MB";
     return(currentMemInfo);
 }
Exemplo n.º 2
0
        public void OnImage(smartar.ImageHolder imageHolder, ulong timestamp)
        {
            // save still image
            m_CaptureImageName = string.Format("{0}/capture_image_{1}.jpg", m_CaptureImagePath, DateTime.Now.ToString("d-MM-yyyy-HH-mm-ss-f"));
            int bufSize = imageHolder.getImageSizeInBytes();

            if (bufSize > 0)
            {
                smartar.Image image = new smartar.Image();
                image.pixels_ = Marshal.AllocHGlobal(bufSize);
                imageHolder.getImage(ref image, bufSize, m_Smart);
#if UNITY_IPHONE && !UNITY_EDITOR
                _SaveJpegToCameraRoll(image.pixels_, bufSize);
#elif UNITY_ANDROID && !UNITY_EDITOR
                byte[] jpegData = new byte[bufSize];
                Marshal.Copy(image.pixels_, jpegData, 0, bufSize);
                File.WriteAllBytes(m_CaptureImageName, jpegData);
                using (AndroidJavaObject utils = new AndroidJavaObject("com.sony.smartar.unsupportedutils.UnsupportedUtils"))
                {
                    var scanFilePath = utils.CallStatic <string>("moveToExternalDir", m_CaptureImageName);
                    if (string.IsNullOrEmpty(scanFilePath))
                    {
                        return;
                    }
                    utils.CallStatic("scanCaptureImage", scanFilePath);
                }
#elif UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN
                m_CaptureImageName = string.Format("{0}/capture_image_{1}.bmp", m_CaptureImagePath, DateTime.Now.ToString("d-MM-yyyy-HH-mm-ss-f"));
                byte[] bitmapData = new byte[bufSize];
                Marshal.Copy(image.pixels_, bitmapData, 0, bufSize);
                File.WriteAllBytes(m_CaptureImageName, bitmapData);
#endif
                Marshal.FreeHGlobal(image.pixels_);
            }
        }
Exemplo n.º 3
0
    /// <summary>
    /// ローカルPush予約処理.
    /// 同タグの場合でも複数回送付可能.
    /// </summary>
    /// <param name="message">Message.</param>
    /// <param name="infotime">Infotime.</param>
    /// <param name="tag">Tag.</param>
    public static void reserveLocalPush(string message, int infotime, int tag)
    {
        // Platform毎に処理分け.
        switch (Application.platform)
        {
        case (RuntimePlatform.OSXEditor):
            break;

        case (RuntimePlatform.Android):
#if UNITY_ANDROID
            Debug.Log(String.Format("message:{0}, infotime:{1}, tag:{2}", message, infotime, tag));
            androidLocalNotificationInit();
            using (alartSender) {
                // Android用ローカル通知を実行。ルームは秒単位の値で定義されているのでミリ秒に変換(*1000)を行う。
                alartSender.CallStatic("localPushInJava", activity, Config.PackageName,
                                       "", "", "app_icon", "", message, (long)(infotime * 1000), tag, "", true);
            }
#endif
            break;

        case (RuntimePlatform.IPhonePlayer):
            Debug.Log(String.Format("message:{0}, infotime:{1}, tag:{2}", message, infotime, tag));
#if UNITY_IPHONE
            reserveLocalNotification(message, infotime, tag);
#endif
            break;
        }
    }
Exemplo n.º 4
0
        public static void SaveImgToAndroid(string albumName, string fileName, byte[] imagebytes)
        {
            string destination = GetAndroidAlbumPath(albumName, false);

            destination = destination + "/" + fileName;
            try
            {
                File.WriteAllBytes(destination, imagebytes);
            }
            catch (Exception ex)
            {
                Debug.LogError("SaveImgToAndroid : " + ex.Message);
            }

            AndroidJavaObject ajo = PTAndroidInterface.Instance.GetPTCustomJavaObj();

            if (SystemInfo.deviceModel.ToLower().Contains("meizu") || SystemInfo.deviceModel.ToLower().Contains("vivo") ||
                SystemInfo.deviceModel.ToLower().Contains("gionee"))
            {
                ajo.CallStatic("ScanSDCardFile", destination, PTAndroidInterface.Instance.GetAndroidJavaObj(), true);
            }
            else
            {
                ajo.CallStatic("ScanSDCardFile", destination, PTAndroidInterface.Instance.GetAndroidJavaObj(), false);
            }
        }
    public override void initialization(string language, GrammarFileStruct [] grammars, string keyword)
    {
        this.onRecieveLogMess("start initialization");
        this.getBaseGrammar(grammars);

        var javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        var currentActivity = javaUnityPlayer.GetStatic <AndroidJavaObject>("currentActivity");

        _recognizerActivity = new AndroidJavaObject("com.sss.breter.voicerecognizer.MainActivity", currentActivity);  //unity.GetStatic< AndroidJavaObject >( "com.sss.breter.voicerecognizer.MainActivity" );
        if (_recognizerActivity == null)
        {
            this.onError("empty java object");
            this.initResult.Invoke(false);
            this.onInitResult(FALSE);
            return;
        }
        #region инициализируем колбэк из jar библиотеки
        try {
            _recognizerActivity.CallStatic(JavaWrapperMethodNames.SET_RECIEVER_OBJECT_NAME.ToString( ), this.gameObject.name);
        } catch (Exception ex) {
            this.onError(ex.Message);
        }
        _recognizerActivity.CallStatic(JavaWrapperMethodNames.SET_LOG_RECIEVER_METHOD_NAME, "onRecieveLogMess");
        _recognizerActivity.CallStatic(JavaWrapperMethodNames.SET_RECOGNITION_RESULT_RECIEVER_METHOD, "onRecognitionResult");
        _recognizerActivity.CallStatic(JavaWrapperMethodNames.SET_CRASH_MESS_RECIEVER_METHOD, "onError");
        _recognizerActivity.CallStatic(JavaWrapperMethodNames.SET_INITIALIZATION_COMPLETE_METHOD, "onInitResult");
        #endregion
        _recognizerActivity.Call(JavaWrapperMethodNames.SET_BASE_GRAMMAR_FILE, _baseGrammar);
        //_recognizerActivity.Call( JavaWrapperMethodNames.SET_TIMEOUT_INTERVAL, this._interval );
        _recognizerActivity.Call(JavaWrapperMethodNames.RUN_RECOGNIZER_SETUP, language);
        _phonesDict = getWordsPhones(language, ref grammars, ref keyword);
        _grammars   = grammars;
        _keyword    = keyword;
    }
Exemplo n.º 6
0
    // Use this for initialization
    void Start()
    {
        using (AndroidJavaObject jc = new AndroidJavaObject("xyz.peke2.myfirstplugin.Hello"))
        {
            string word = jc.CallStatic <string>("say");
            Debug.Log("plugintest:say()=>" + word);
            int sum = jc.CallStatic <int>("add", 4, 99);
            Debug.Log("plugintest:add(4,99)=>" + sum.ToString());

            using (AndroidJavaObject param = new AndroidJavaObject("xyz.peke2.myfirstplugin.HelloParam")) {
                param.Set <int[]>("values", new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
                param.Set <string>("name", "Parameter");
                //int total = jc.CallStatic<int>("sum", param);
                //Debug.Log("plugintest:sum=>" + total.ToString());
                //int[] values = param.Get<int[]>("values");
                //Debug.Log("plugintest:value=>" + values[3].ToString());
                //string name = jc.CallStatic<string>("getName", param);
                //Debug.Log("plugintest:name=>" + name);
            }
        }

        AndroidJavaClass  unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject context     = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");

        using (AndroidJavaObject vib = new AndroidJavaObject("xyz.peke2.myfirstplugin.Vibration", context)) {
            bool is_enabled = vib.Call <bool>("hasFunction");
            Debug.Log("plugintest:vib=>" + is_enabled.ToString());
            bool has_amplitude = vib.Call <bool>("hasAmplitudeControl");
            Debug.Log("plugintest:amplitude=>" + has_amplitude.ToString());

            vib.Call("oneShot", 3000, 16);
        }
    }
Exemplo n.º 7
0
    void OnGUI()
    {
        // 이렇게 접근하는 방법은, static이나 non-static 모두
        // 동일한 방법으로 접근 가능하다
        if (GUI.Button(new Rect(100, 100, 100, 50), "StaticInt"))
        {
            messge += ("\n" + myObj.CallStatic <int>("GetStaticInt", 123).ToString());
        }

        if (GUI.Button(new Rect(100, 200, 100, 50), "StaticString"))
        {
            messge += ("\n" + myObj.CallStatic <string>("GetStaticString", "StaticString"));
        }

        if (GUI.Button(new Rect(100, 300, 100, 50), "Int"))
        {
            messge += ("\n" + myObj.Call <int>("GetInt", 456).ToString());
        }

        if (GUI.Button(new Rect(100, 400, 100, 50), "String"))
        {
            messge += ("\n" + myObj.Call <string>("GetString", "String"));
        }

        GUI.Label(new Rect(Screen.width / 2 - 350, Screen.height / 2 - 150, 700, 300), messge);
    }
Exemplo n.º 8
0
    public static void InitPurchaseSDK(string url, string userID, string platformType, string productIdJsonArray, string gameID, string token, string scene = null)
    {
        Debug.Log("into InitPurchaseSDK");
        Debug.Log("url " + url);
        Debug.Log("userID " + userID);
        Debug.Log("platformType " + platformType);
        Debug.Log("productIdJsonArray " + productIdJsonArray);
        Debug.Log("gameID " + gameID);
        Debug.Log("token " + token);
        Debug.Log("scene " + scene);
        Debug.Log("base64PublicKey " + base64PublicKey);

        isUseStaticInit = true;

        if (Instance == null)
        {
            Debug.Log("Initialize SdkdsPurchase");
            GameObject gameobject = GameObject.Find("PurchaseUtil");
            if (gameobject == null)
            {
                gameobject = new GameObject("PurchaseUtil");
            }
            if (gameobject != null)
            {
                gameobject.AddComponent <SdkdsPurchaseUtils> ();
            }
        }

#if (UNITY_EDITOR || DISBLE_PLATFORM)
#elif UNITY_ANDROID
        gpPaySdkUtils_unity = SdkdsPurchaseUtils.LoadJavaClass("com.sdkds.gppay.PaySdk");
        // set debug
        Instance.setDebug(isDebugMode);
        //game object that can receive unity msg
        string unity_msg_receiver = "PurchaseUtil";

        if (scene == null)
        {
            gpPaySdkUtils_unity.CallStatic("SdkdsInitPurchase", SingletonHolder.instance_context, base64PublicKey, url, gameID, userID, platformType, productIdJsonArray, token, unity_msg_receiver);
        }
        else
        {
            gpPaySdkUtils_unity.CallStatic("SdkdsInitPurchase", SingletonHolder.instance_context, base64PublicKey, url, gameID, userID, platformType, productIdJsonArray, token, scene, unity_msg_receiver);
        }
#elif UNITY_IOS || UNITY_IPHONE
        SDKDSInitPurchaseUtils();
        if (scene == null)
        {
            Debug.Log("init Static Purchase scene is null");
            SDKDSInitPurchase(url, userID, platformType, productIdJsonArray, gameID, token);
        }
        else
        {
            Debug.Log("init Static Purchase scene is " + scene);
            SDKDSInitPurchase(url, userID, platformType, productIdJsonArray, gameID, token, scene);
        }
#else
#endif
    }
Exemplo n.º 9
0
 /// <summary>
 /// Gives callback with verification status when session starts successfully on objectMethod. Note: Won't trigger if object not active/destroyed
 /// </summary>
 /// <param name="key">App key</param>
 /// <param name="objectName">Name of the object currently active in scene</param>
 /// <param name="objectMethod">Method inside script attached to the object</param>
 public static void StartWithKeyCallback(string key, string objectName, string objectMethod)
 {
     if (Application.platform == RuntimePlatform.Android)
     {
         StartWithKey(key);
     }
     jw.CallStatic("onVerificationListener", objectName, objectMethod);
 }
Exemplo n.º 10
0
 public void StartSDK(string json)
 {
     using (AndroidJavaObject plugin = new AndroidJavaObject("com.fyber.unity.FyberPlugin"))
     {
         plugin.CallStatic("setPluginParameters", Fyber.Version, Application.unityVersion);
         plugin.CallStatic("start", json);
     }
 }
Exemplo n.º 11
0
 // Use this for initialization
 void Start()
 {
     using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
         witUtilityActivity = jc.GetStatic <AndroidJavaObject>("currentActivity");
     }
     //Wit.Call("init","");
     witUtilityActivity.CallStatic("setGameObjectName", gameObject.name);
     witUtilityActivity.CallStatic("setAccessToken", "KEG6DZE66ZYDLVQELWXCMNQ7HLFTKRAF");
 }
Exemplo n.º 12
0
        internal static string pvr_Error_GetMessage(AndroidJavaObject popMessage)
        {
            string returnValue = "";

#if UNITY_ANDROID
            returnValue = errorHandle.CallStatic <string>("pvr_Error_GetMessage", popMessage);
#endif
            return(returnValue);
        }
Exemplo n.º 13
0
    /// <summary>
    /// 获取CPU名字
    /// </summary>
    /// <returns></returns>
    public string getCPUName()
    {
        if (_javaSysHardwareInfoObj != null)
        {
            return(_javaSysHardwareInfoObj.CallStatic <string>("getCPUName"));
        }

        return("");
    }
Exemplo n.º 14
0
        //iOS Android Universal API



        public static void track(String eventName)
        {
#if UNITY_EDITOR
#elif UNITY_IPHONE
            _track(eventName);
#elif UNITY_ANDROID
            _DplusAgent.CallStatic("track", Context, eventName);
#endif
        }
 public void CallStatic(string method, params object[] args)
 {
     if (Application.platform == RuntimePlatform.Android)
     {
         AndroidJNI.PushLocalFrame(args.Length + 1);
         jo.CallStatic(method, args);
         AndroidJNI.PopLocalFrame(System.IntPtr.Zero);
     }
 }
        public string SendMessage(MethodCall methodCall)
        {
            if (_androidPlugin != null)
            {
                return(_androidPlugin.CallStatic <string>("unityMessage", methodCall.ToJsonString()));
            }

            return(null);
        }
Exemplo n.º 17
0
    //method that calls our native plugin.
    public void CallNativePlugin(int type)
    {
        try
        {
            debugLog("CallNativePlugin");

            // Retrieve the UnityPlayer class.
            AndroidJavaClass unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");

            if (unityPlayerClass != null)
            {
                debugLog("unityPlayerClass: load");
            }

            // Retrieve the UnityPlayerActivity object ( a.k.a. the current context )
            AndroidJavaObject unityActivity = unityPlayerClass.GetStatic <AndroidJavaObject>("currentActivity");

            if (unityActivity != null)
            {
                debugLog("unityActivity: load");
            }

            // Retrieve the "Bridge" from our native plugin.
            // Define the complete package name.
            AndroidJavaObject bridge = new AndroidJavaObject("com.phaneronsoft.messagelib.MessageUtil");

            if (bridge != null)
            {
                debugLog("bridge: load");
            }

            if (type == 0)
            {
                // Setup the parameters we want to send to our native plugin.
                object[] parameters = new object[2];
                parameters[0] = unityActivity;
                parameters[1] = "4";

                // Call PrintString in bridge, with our parameters.
                bridge.CallStatic("sendMessenger", parameters);
            }
            else if (type == 1)
            {
                // Setup the parameters we want to send to our native plugin.
                object[] parameters = new object[3];
                parameters[0] = unityActivity;
                parameters[1] = "447700900000";
                parameters[2] = "Hello World!";

                // Call PrintString in bridge, with our parameters.
                bridge.CallStatic("sendWhatsapp", parameters);
            }
        } catch (Exception e)
        {
            debugLog("Exception: " + e);
        }
    }
Exemplo n.º 18
0
    /// <summary>
    ///  reported infoc data
    ///  NOTE: Must be set every field's value except network. In order to report a unified network type definition, the caller does not need to set network field, this Api appends the network field by default.
    ///
    ///  For example:
    ///  suppose in our kfmt.dat file have difine an report format:
    ///  cmplaysdk_purchases:108 uptime:int64 network:byte action:byte source:byte orderid:string productid:string remark:string
    ///  "cmplaysdk_purchases" is infoc table name, 108 is version number of this table, "uptime:int64 network:byte action:byte source:byte orderid:string productid:string remark:string" is the field and type definition
    ///  then you can do an report by following example code:
    ///
    ///  string tableName = "cmplaysdk_purchases";
    ///  string data = "uptime=1522308228&action=1&source=2&orderid=GPA.3306-9888-6774-74667&productid=diamonds_3280&remark=1";     //NOTE: must be set every field's value except network
    ///  ReportData(tableName, data);
    ///
    /// </summary>
    /// <param name="tableName">table name</param>
    /// <param name="data">data, format:key=value&key=value,e.g.:uptime=1113213&action=3&remark=abc</param>
    public void ReportData(string tableName, string data)
    {
#if (UNITY_EDITOR || DISBLE_PLATFORM)
#elif UNITY_IOS || UNITY_IPHONE
        CMPReportData(tableName, data);
#elif UNITY_ANDROID
        reportUtils.CallStatic("reportData", tableName, data);
#else
#endif
    }
Exemplo n.º 19
0
    //-------------------------------------------------------------------------
    public string getCountryCode()
    {
        string code = null;

        if (mAndroidFun != null)
        {
            code = mAndroidFun.CallStatic <string>("getCountryZipCode");
        }
        return(code);
    }
Exemplo n.º 20
0
 // VibrationEffect CreateOneShot(long milliseconds, int amplitude)
 public static AndroidJavaObject CreateOneShot(long milliseconds, int amplitude)
 {
     if (IsAndroid())
     {
         return(vibrationEffectClass.CallStatic <AndroidJavaObject>("CreateOneShot", new object[] { milliseconds, amplitude }));
     }
     else
     {
         return(null);
     }
 }
 /// <summary>
 /// 离线命令词,在线不需要调用
 /// </summary>
 /// <param name="json">详情请移步 https://ai.baidu.com/ai-doc/SPEECH/9k38lxfnk </param>
 public override void LoadOfflineEngine(string json)
 {
     if (m_AsrJavaObject != null)
     {
         m_AsrJavaObject.CallStatic("LoadOfflineEngine", json);
     }
     else
     {
         Debug.LogWarning(GetType() + "/LoadOfflineEngine()/ m_AsrJavaObject is null!");
     }
 }
Exemplo n.º 22
0
    public void Init()
    {
        var jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        var jo = jc.GetStatic <AndroidJavaObject>("currentActivity");

        var drummondHelper = new AndroidJavaObject("com.help.drummond.helper.DrummondHelper");

        drummondHelper.CallStatic("initFullDebugMode", jo);

        _androidObject = drummondHelper.CallStatic <AndroidJavaObject>("getDrummond");
    }
Exemplo n.º 23
0
 public void Register(int id, string name, string title, string content, int triggerTime, bool repeat)
 {
     m_javaObj.CallStatic("Register", new object[6] {
         id,
         name,
         title,
         content,
         triggerTime,
         repeat
     });
 }
Exemplo n.º 24
0
    //单屏登录
    public void SingleLogin()
    {
#if !UNITY_EDITOR && UNITY_ANDROID
        Init();
        javaObject.CallStatic("mjCallSingleLogin");
#endif
        Debug.Log("SingleLogin");
    }
Exemplo n.º 25
0
    public void Purchase(string bundleID, int amount, string userID)
    {
        currentBundleID = int.Parse(bundleID);

        using (AndroidJavaClass cls = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
        {
            using (AndroidJavaObject obj_Activity = cls.GetStatic <AndroidJavaObject>("currentActivity"))
            {
                cls_StorePurchaser.CallStatic("makePurchase", obj_Activity, GetProductIDFromBundleID(currentBundleID));
            }
        }
    }
Exemplo n.º 26
0
        /// <summary>
        /// Update an already scheduled notification.
        /// If a notification with the specified id was already scheduled it will be overridden with the information from the passed notification struct.
        /// </summary>
        public static void UpdateScheduledNotification(int id, AndroidNotification notification, string channel)
        {
            if (!Initialize())
            {
                return;
            }

            if (notificationManager.CallStatic <bool>("checkIfPendingNotificationIsRegistered", id))
            {
                SendNotification(id, notification, channel);
            }
        }
 /// <summary>
 /// 开始唤醒词功能
 /// </summary>
 /// <param name="wakeUpPath">唤醒词库路径(Plugins/Android/assets路径下的.bin文件)需要加后缀名</param>
 public override void Begin(string wakeUpPath)
 {
     if (m_WakeupJavaObject != null)
     {
         string path = "assets://" + wakeUpPath;
         m_WakeupJavaObject.CallStatic("Start", path);
     }
     else
     {
         Debug.LogWarning(GetType() + "/Start()/ m_WakeupJavaObject is null!");
     }
 }
Exemplo n.º 28
0
        // =============================================================================

        #region Utils
#if UNITY_ANDROID && !UNITY_EDITOR
        public void CallStaticMethod(AndroidJavaObject obj, string methodName, object[] methodParams)
        {
            if (IsAvailable(methodParams))
            {
                obj.CallStatic(methodName, methodParams);
            }
            else
            {
                obj.CallStatic(methodName);
            }
            obj.Dispose();
        }
Exemplo n.º 29
0
 /// <summary>
 /// Inits the SDK.
 /// </summary>
 /// <param name="sdkConfig">Sdk config.</param>
 public override void initSDK(SdkConfig sdkConfig)
 {
     Debug.Log("AndroidSDKImpl  ===>>>  initSDK === appID:" + sdkConfig.appID + "|appSecretKey:" + sdkConfig.appSecretKey);
     if (javaObj != null)
     {
         javaObj.CallStatic("initSDK", sdkConfig.appID, sdkConfig.appSecretKey);
     }
     else
     {
         Debug.Log(SDK_JAVA_CLASS + "  ===>>>  javaObj is null!");
     }
 }
Exemplo n.º 30
0
    /// <summary>
    /// get key value from cloud
    /// </summary>
    /// <param name="func_type">cloud key's func_type</param>
    /// <param name="section">cloud key's section name</param>
    /// <param name="key">cloud key's key name</param>
    /// <param name="defValue">cloud key's default value</param>
    /// <returns></returns>
    public int getIntValue(int func_type, string section, string key, int defValue)
    {
#if (UNITY_EDITOR || DISBLE_PLATFORM)
        return(0);
#elif UNITY_IOS || UNITY_IPHONE
        return(CMPGetCloudIntValue(func_type, section, key, defValue));
#elif UNITY_ANDROID
        return(cloud_hepler_unity.CallStatic <int>("getIntValue", func_type, section, key, defValue));
#else
        return(0);
#endif
    }