Ejemplo n.º 1
0
        /*
         * PointerIcon pointerIcon = PointerIcon.getSystemIcon(this, PointerIcon.TYPE_NULL);
         * getWindow().getDecorView().setPointerIcon(pointerIcon);
         */
        public static void SetCursor(CursorType cursorType)
        {
            AndroidJavaClass PointerIcon = new AndroidJavaClass("android.view.PointerIcon");

            AndroidJavaObject pointerIcon = PointerIcon.CallStatic <AndroidJavaObject>("getSystemIcon", UnityAppContext, cursorType);

            UnityActivity.Call <AndroidJavaObject>("getWindow").Call <AndroidJavaObject>("getDecorView").Call("setPointerIcon", pointerIcon);
        }
Ejemplo n.º 2
0
        /*添加权限 <permission android:name="android.permission.DELETE_PACKAGES" />
         * public static void unstallApp(Context context,String packageName){
         *  Intent uninstall_intent = new Intent(Intent.ACTION_DELETE);
         *  uninstall_intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
         *  uninstall_intent.setData(Uri.parse("package:"+packageName));
         *  context.startActivity(uninstall_intent);}    */
        /// <summary>
        /// 卸载app
        /// </summary>
        /// <param name="packageName"></param>
        public static void UnstallApp(string packageName)
        {
            AndroidJavaClass  Intent       = new AndroidJavaClass("android.content.Intent");
            AndroidJavaClass  Uri          = new AndroidJavaClass("android.net.Uri");
            AndroidJavaObject intentDelete = new AndroidJavaObject("android.content.Intent", Intent.GetStatic <AndroidJavaObject>("ACTION_DELETE"));
            //intentDelete.Call<AndroidJavaObject>("setFlags", Intent.GetStatic<AndroidJavaObject>("FLAG_ACTIVITY_NEW_TASK"));
            AndroidJavaObject uri = Uri.CallStatic <AndroidJavaObject>("parse", ("package:" + packageName).ToJavaString());

            intentDelete.Call <AndroidJavaObject>("setData", uri);
            UnityActivity.Call("startActivity", intentDelete);
        }
Ejemplo n.º 3
0
        public void ShowToast(string InContent)
        {
#if !UNITY_EDITOR && UNITY_ANDROID
            UnityActivity.Call("runOnUiThread", new AndroidJavaRunnable(() =>
            {
                toast.CallStatic <AndroidJavaObject>("makeText",
                                                     UnityContext,
                                                     InContent,
                                                     showToastTime).Call("show");
            }));
#endif
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取WiFi状态
        /// </summary>
        /// <returns></returns>
        public static string GetWIFIState()
        {
            WiFiState         state       = WiFiState.WIFI_STATE_UNKNOWN;
            AndroidJavaObject wifiManager = UnityActivity.Call <AndroidJavaObject>("getSystemService", "wifi".ToJavaString());

            if (wifiManager != null)
            {
                int wifiState = wifiManager.Call <int>("getWifiState");
                state = (WiFiState)wifiState;
            }
            return(state.ToString());
        }
Ejemplo n.º 5
0
        //http://www.manew.com/thread-97298-1-1.html
        //path为.apk文件的完整路径
        public static void InstallAPP(string path)
        {
            AndroidJavaClass Intent = new AndroidJavaClass("android.content.Intent");
            AndroidJavaClass Uri    = new AndroidJavaClass("android.net.Uri");

            AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent", Intent.GetStatic <AndroidJavaObject>("ACTION_VIEW"));
            AndroidJavaObject uri    = Uri.CallStatic <AndroidJavaObject>("fromFile", new AndroidJavaObject("java.io.File", path.ToJavaString()));

            //apk MIME类型为:"application/vnd.android.package-archive",参考https://blog.csdn.net/boom_jia/article/details/52814914
            intent.Call <AndroidJavaObject>("setDataAndType", uri, "application/vnd.android.package-archive".ToJavaString());
            UnityActivity.Call("startActivity", intent);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取原生类型: android.provider.Settings中的属性,以android_id为例(只要系统有写就可以)
        /// </summary>
        /// <returns></returns>
        public static string GetAndroidID()
        {
            string android_id = "NONE";

            try
            {
                AndroidJavaObject contentResolver = UnityActivity.Call <AndroidJavaObject>("getContentResolver");
                AndroidJavaClass  secure          = new AndroidJavaClass("android.provider.Settings$Secure");
                //CallStatic 的使用:静态方法获取一个Android原生类型
                android_id = secure.CallStatic <string>("getString", contentResolver, "android_id");
            }
            catch (System.Exception e)
            {
                Debug.LogError(e);
            }

            return(android_id);
        }
Ejemplo n.º 7
0
        /**  安卓方法
         * 2.设置 APP界面屏幕亮度值方法
         **
         **Activity act;
         **private void setAppScreenBrightness(int birghtessValue)
         **{
         ** Window window = act.getWindow();
         ** WindowManager.LayoutParams lp = window.getAttributes();
         ** lp.screenBrightness = birghtessValue / 255.0f;
         ** window.setAttributes(lp);
         **}
         */
        //Brightness的有效范围是0~1,-1。 若设置为-1则跟随系统亮度
        //模拟器上厕所无效  应该没问题
        public static void SetAppScreenBrightness(float birghtessValue)
        {
            RunOnUIThread(() =>
            {
                AndroidJavaObject window = UnityActivity.Call <AndroidJavaObject>("getWindow");
                AndroidJavaObject lp     = window.Call <AndroidJavaObject>("getAttributes");

                if (birghtessValue != -1f)
                {
                    birghtessValue = Mathf.Clamp01(birghtessValue);
                }
                lp.Set("screenBrightness", birghtessValue);
                window.Call("setAttributes", lp);

                //debug
                //float b = lp.Get<float>("screenBrightness");
                //AndroidLogI("Brightness:" + b.ToString());
            });
        }
Ejemplo n.º 8
0
        public DeviceInfo()
        {
#if UNITY_EDITOR
#elif UNITY_ANDROID
            UnityPlayer   = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            UnityActivity = UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            UnityContext  = UnityActivity.Call <AndroidJavaObject>("getApplicationContext");
            toast         = new AndroidJavaClass("android.widget.Toast");
            showToastTime = toast.GetStatic <int>("LENGTH_SHORT");
#endif

            if (PlayerPrefs.GetInt(IS_GET_DEVICE_INFO, 0) == 0)
            {
                GetDeviceInfo();
            }
            UniqueId        = PlayerPrefs.GetString(UNIQUE_ID);
            Country         = PlayerPrefs.GetString(COUNTRY);
            Language        = PlayerPrefs.GetString(LANGUAGE);
            OperatingSystem = PlayerPrefs.GetString(OPERATING_SYSTEM);
            Model           = PlayerPrefs.GetString(MODEL);
            ScreenSize      = PlayerPrefs.GetString(SCREEN_SIZE);
            Memory          = PlayerPrefs.GetString(MEMORY);
        }
Ejemplo n.º 9
0
 //设置不自动锁屏
 public static void DisableScreenLock()
 {
     UnityActivity.Call <AndroidJavaObject>("getWindow").Call("addFlags", 128);
     //讲解:call("方法名",参数1);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 获取当前app包名
 /// </summary>
 /// <returns></returns>
 public static string getPackageName()
 {
     return(UnityActivity.Call <string>("getPackageName"));
     //讲解:call<返回值类型>("方法名");
 }
Ejemplo n.º 11
0
 /// <summary>
 /// UI线程中运行
 /// </summary>
 /// <param name="r"></param>
 public static void RunOnUIThread(AndroidJavaRunnable r)
 {
     UnityActivity.Call("runOnUiThread", r);
 }