Example #1
0
        public static void start()
        {
            try
            {
                string tmp = getTmpDir();

                if (Directory.Exists(tmp))
                {
                    Directory.Delete(tmp, true);
                }

                ToolMobile.createDir(tmp);
            }
            catch (Exception exc)
            {
                ToolMobile.setExceptionInner(exc);
            }
        }
Example #2
0
 public static void restartEnvironment()
 {
     try
     {
         ToolMobile.setEnvironment(null);
     }
     catch (Exception exc)
     {
         ToolMobile.setExceptionInner(exc);
     }
     try
     {
         getEnvironment();
     }
     catch (Exception exc)
     {
         ToolMobile.setExceptionInner(exc);
     }
 }
 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
 {
     ToolMobile.setExceptionInner(e.ExceptionObject as Exception);
 }
Example #4
0
                internal bool openBT()
                {
                    BluetoothAdapter mBluetoothAdapter = getAdapter();
                    BluetoothDevice  mmDevice          = null;


                    if (mBluetoothAdapter == null)
                    {
                        ToolMobile.log("no bt adapter");

                        ToolMsg.show(null, MessageCollection.T_MSG_ERROR_CONNECTION + " [BLUETOOTH]", null);
                        return(false);
                    }



                    if (!mBluetoothAdapter.IsEnabled)
                    {
                        ToolMobile.log("enable bt adapter");

                        mBluetoothAdapter.Enable();

                        for (int i = 0; i < 15; ++i)
                        {
                            if (mBluetoothAdapter.IsEnabled)
                            {
                                break;
                            }
                            Thread.Sleep(100);
                        }


                        if (!mBluetoothAdapter.IsEnabled)
                        {
                            ToolMsg.show(null, MessageCollection.T_MSG_ERROR_CONNECTION + " [BLUETOOTH]", null);
                            return(false);
                        }
                    }

                    List <string> list = new List <string>();

                    foreach (BluetoothDevice dev_ in mBluetoothAdapter.BondedDevices)
                    {
                        list.Add(dev_.Name);

                        if (dev_.Name == CurrentVersion.ENV.getPrinter())
                        {
                            mmDevice = dev_;
                            break;
                        }
                    }



                    if (mmDevice == null)
                    {
                        string[] arr_ = list.ToArray();
                        ToolMsg.askList(null, arr_, (o, e) =>
                        {
                            if (e.Which >= 0 && e.Which < arr_.Length)
                            {
                                CurrentVersion.ENV.setPrinter(arr_[e.Which]);
                            }
                        });

                        // ToolMsg.show(null, MessageCollection.T_MSG_ERROR_NO_DATA + " BLUETOOTH = [" + CurrentVersion.ENV.getPrinter() + "]", null);
                        return(false);
                    }

                    try
                    {
                        //mBluetoothAdapter.StartDiscovery();
                        //for (int i = 0; i < 10; ++i)
                        //{
                        //    if (mBluetoothAdapter.IsDiscovering)
                        //        break;
                        //    Thread.Sleep(100);

                        //}

                        // UUID uuid = UUID.FromString("00001101-0000-1000-8000-00805f9b34fb");


                        IntPtr createRfcommSocket = JNIEnv.GetMethodID(mmDevice.Class.Handle, "createRfcommSocket", "(I)Landroid/bluetooth/BluetoothSocket;");

                        IntPtr _socket = JNIEnv.CallObjectMethod(mmDevice.Handle, createRfcommSocket, new Android.Runtime.JValue(1));

                        mmSocket = Java.Lang.Object.GetObject <BluetoothSocket>(_socket, JniHandleOwnership.TransferLocalRef);

                        mBluetoothAdapter.CancelDiscovery();

                        mmSocket.Connect();

                        //           Method m = mmDevice.GetType().GetMethod("CreateRfcommSocket", new Type[] {int.class});
                        //tmp = (BluetoothSocket) m.invoke(device, 1);

                        // mmSocket = mmDevice.CreateRfcommSocketToServiceRecord(uuid);


                        // mmSocket.Connect();

                        //time out not supported
                        // mmInputStream.ReadTimeout = mmInputStream.WriteTimeout = mmOutputStream.ReadTimeout = mmOutputStream.WriteTimeout = 5000;
                        return(true);
                    }
                    catch (Exception exc)
                    {
                        ToolMobile.log(exc.ToString());
                        ToolMobile.setExceptionInner(exc);
                    }
                    finally
                    {
                    }

                    return(false);
                }