Exemple #1
0
        protected override void Close(Object data)
        {
            var stream = InputStreamInvoker.FromJniHandle(((InputStream)data).Handle, JniHandleOwnership.DoNotTransfer);

            Close(stream);
        }
        public async Task <bool> ConnectAsync(string _deviceName)
        {
            try
            {
                BluetoothAdapter adapter = BluetoothAdapter.DefaultAdapter;
                if (adapter == null)
                {
                    Log("No Bluetooth adapter found.");
                }
                else if (!adapter.IsEnabled)
                {
                    Log("Bluetooth adapter is not enabled.");
                }

                List <BluetoothDevice> L = new List <BluetoothDevice>();
                foreach (BluetoothDevice d in adapter.BondedDevices)
                {
                    Log("D: " + d.Name + " " + d.Address + " " + d.BondState.ToString());
                    L.Add(d);
                }

                BluetoothDevice device = null;
                device = L.Find(j => j.Name == _deviceName);

                if (device == null)
                {
                    Log("Named device not found.");
                }
                else
                {
                    Log("Device has been found: " + device.Name + " " + device.Address + " " + device.BondState.ToString());
                }

                socket = device.CreateRfcommSocketToServiceRecord(UUID.FromString(TARGET_UUID));
                await socket.ConnectAsync();

                if (socket != null && socket.IsConnected)
                {
                    Log("Connection successful!");
                }
                else
                {
                    Log("Connection failed!");
                }

                inStream  = (InputStreamInvoker)socket.InputStream;
                outStream = (OutputStreamInvoker)socket.OutputStream;

                if (socket != null && socket.IsConnected)
                {
                    Task t = new Task(() => Listen(inStream));
                    t.Start();

                    //Task t1 = new Task(() => PingEvent());
                    //t1.Start();
                }
                else
                {
                    //throw new Exception("Socket not existing or not connected.");
                }
            }
            catch (Exception e)
            {
                //throw new Exception("Socket not existing or not connected.");
            }

            return(socket.IsConnected);
        }
Exemple #3
0
        bool IResourceDecoder.Handles(Object source, Options options)
        {
            var stream = InputStreamInvoker.FromJniHandle(source.Handle, JniHandleOwnership.DoNotTransfer);

            return(Handles(stream, options));
        }
Exemple #4
0
        IResource IResourceDecoder.Decode(Object source, int width, int height, Options options)
        {
            var stream = InputStreamInvoker.FromJniHandle(source.Handle, JniHandleOwnership.DoNotTransfer);

            return(Decode(stream, width, height, options));
        }
Exemple #5
0
 internal static JsonValue Load(InputStreamInvoker stream)
 {
     throw new NotImplementedException();
 }
Exemple #6
0
        protected override void OnCreate(Bundle savedInstanceState)


        {
            base.OnCreate(savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Menu);


            // Get the latitude/longitude EditBox and button resources:

            EditText quiz01 = FindViewById <EditText>(Resource.Id.qText);
            EditText quiz02 = FindViewById <EditText>(Resource.Id.quText);
            Button   button = FindViewById <Button>(Resource.Id.getDataButton);

            // When the user clicks the button ...
            button.Click += async(sender, e) =>
            {
                // Get the latitude and longitude entered by the user and create a query.
                string url = "http://http://introtoapps.com/quizzes_sample.json/findNearByDataJSON?q=" +
                             quiz01.Text +
                             "&qu=" +
                             quiz02.Text +
                             "&username=json";

                // Fetch the weather information asynchronously,
                // parse the results, then update the screen:
                JsonValue json = await FetchDataAsync(url);

                // ParseAndDisplay (json);
            };


            {
                // Create your application here

                var xx = _database.GetUser(1);

                Toast.MakeText(this, "Welcome " + xx.Name, ToastLength.Long).Show();
            }

            ///Gets weather data from the passed URL.

            async Task <JsonValue> FetchDataAsync(string url)
            {
                // Create an HTTP web request using the URL:
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));

                request.ContentType = "application/json";
                request.Method      = "GET";

                // Send the request to the server and wait for the response:
                using (WebResponse response = await request.GetResponseAsync())
                {
                    // Get a stream representation of the HTTP web response:
                    using (InputStreamInvoker stream = (Android.Runtime.InputStreamInvoker)response.GetResponseStream())
                    {
                        // Use this stream to build a JSON document object:
                        JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));

                        Console.Out.WriteLine("Response: {0}", jsonDoc.ToString());

                        // Return the JSON document:
                        return(jsonDoc);
                    }
                }
            }
        }