public void writeData(Java.Lang.String data) { //Extraemos el stream de salida try { outStream = btSocket.OutputStream; } catch (System.Exception e) { System.Console.WriteLine("Error al enviar" + e.Message); } //creamos el string que enviaremos Java.Lang.String message = data; //lo convertimos en bytes byte[] msgBuffer = message.GetBytes(); try { //Escribimos en el buffer el arreglo que acabamos de generar outStream.Write(msgBuffer, 0, msgBuffer.Length); } catch (System.Exception e) { System.Console.WriteLine("Error al enviar" + e.Message); } }
/** Needed for the Digest Access Authentication. */ private System.String computeMd5Hash(Java.Lang.String buffer) { MessageDigest md; try { md = MessageDigest.GetInstance("MD5"); return(bytesToHex(md.Digest(buffer.GetBytes("UTF-8")))); } catch (NoSuchAlgorithmException ignore) { } catch (UnsupportedEncodingException e) {} return(""); }
/// <summary> /// Sends a message. /// </summary> /// <param name='message'> /// A string of text to send. /// </param> private void SendMessage(Java.Lang.String message) { // Check that we're actually connected before trying anything if (connectionService.GetState() != OBDConnectionService.STATE_CONNECTED) { Toast.MakeText(Application.Context, Resource.String.not_connected, ToastLength.Short).Show(); return; } // Check that there's actually something to send if (message.Length() > 0) { // Get the message bytes and tell the BluetoothConnectionService to write byte[] send = message.GetBytes(); connectionService.Write(send); } }
private async void Button_OnClicked(object sender, EventArgs e) { var adapter = BluetoothAdapter.DefaultAdapter; if (adapter == null) { throw new Exception("No Bluetooth adapter found."); } if (!adapter.IsEnabled) { throw new Exception("Bluetooth adapter is not enabled."); } var device = (from bd in adapter.BondedDevices where bd.Name == "PROFYEV" select bd).FirstOrDefault(); if (device == null) { var devices = (from bd in adapter.BondedDevices select bd).ToArray(); } else { var _socket = device.CreateRfcommSocketToServiceRecord(UUID.FromString("00001101-0000-1000-8000-00805f9b34fb")); await _socket.ConnectAsync(); try { var outStream = _socket.OutputStream; var message = new Java.Lang.String("Hello!"); var msgBuffer = message.GetBytes(); outStream.Write(msgBuffer, 0, msgBuffer.Length); } catch (Exception exception) { } //var rssi = _socket.RemoteDevice.; } }
/// <summary> /// Sends a message. /// </summary> /// <param name='message'> /// A string of text to send. /// </param> private void SendMessage(Java.Lang.String message) { // Check that we're actually connected before trying anything if (chatService.GetState() != BluetoothChatService.STATE_CONNECTED) { Toast.MakeText(this, Resource.String.not_connected, ToastLength.Short).Show(); return; } // Check that there's actually something to send if (message.Length() > 0) { // Get the message bytes and tell the BluetoothChatService to write byte[] send = message.GetBytes(); chatService.Write(send); // Reset out string buffer to zero and clear the edit text field outStringBuffer.SetLength(0); } }
private void SendMessage(Java.Lang.String message) { if (chatService.GetState() != BluetoothChatService.STATE_CONNECTED) { Toast.MakeText(this, Resource.String.not_connected, ToastLength.Short).Show(); return; } else if (message.Length() > 0) { // Send message byte[] msg = message.GetBytes(); chatService.Write(msg); // Send EOT character byte[] END_MSG = new Java.Lang.String("~").GetBytes(); chatService.Write(END_MSG); outStringBuffer.SetLength(0); outEditText.Text = string.Empty; } }
public DeviceUuidFactory(Context context) { if (uuid == null) { lock (_lock) { if (uuid == null) { var prefs = context.GetSharedPreferences(PREFS_FILE, FileCreationMode.Private); var id = prefs.GetString(PREFS_DEVICE_ID, null); if (!string.IsNullOrWhiteSpace(id)) { // Use the ids previously computed and stored in the prefs file uuid = UUID.FromString(id); } else { var androidId = Settings.Secure.GetString(context.ContentResolver, Settings.Secure.AndroidId); // Use the Android ID unless it's broken, in which case fallback on deviceId, // unless it's not available, then fallback on a random number which we store // to a prefs file if ("9774d56d682e549c" == androidId) { //Generate a new UUID rather than require READ_PHONE_STATE var c = new Java.Lang.String(androidId); uuid = UUID.NameUUIDFromBytes(c.GetBytes("utf8")); } else { uuid = UUID.RandomUUID(); } prefs.Edit().PutString(PREFS_DEVICE_ID, uuid.ToString()).Apply(); } } } } }
/** * * Método faz a gravação de uma nova mensagem no cartão. * * Essa nova mensagem será códificada usando o padrão UTF-8. * * @param ndef = Contém as informações do cartão que esta sendo lido. * @param mensagem = Mensagem que será gravada no cartão * * @throws IOException * @throws FormatException * * @return boolean => True = Mensagem Gravada / False = Erro ao gravar mensagem * * */ public bool GavarMensagemCartao(Ndef ndef, string mensagem) { bool retorno = false; try { if (ndef != null) { ndef.Connect(); NdefRecord mimeRecord = null; Java.Lang.String str = new Java.Lang.String(mensagem); mimeRecord = NdefRecord.CreateMime ("UTF-8", str.GetBytes(Charset.ForName("UTF-8"))); ndef.WriteNdefMessage(new NdefMessage(mimeRecord)); ndef.Close(); retorno = true; } else { retorno = FormataCartao(ndef); } } catch (System.FormatException e) { throw new System.FormatException(e.Message); } catch (IOException e) { throw new IOException(e.Message); } finally { this.GravaTempoFinal(); } return(retorno); }
public SerialPort(File device, int baudrate, int flags) { // 检查访问权限,如果没有读写权限,进行文件操作,修改文件访问权限 if (!device.CanRead() || !device.CanWrite()) { try { //通过挂在到linux的方式,修改文件的操作权限 Java.Lang.Process su = Runtime.GetRuntime().Exec("/system/xbin/su"); //一般的都是/system/bin/su路径,有的也是/system/xbin/su var cmd = new Java.Lang.String("chmod 777 " + device.AbsolutePath + "\n" + "exit\n"); // Log.e("cmd :", cmd); su.OutputStream.Write(cmd.GetBytes()); if ((su.WaitFor() != 0) || !device.CanRead() || !device.CanWrite()) { throw new SecurityException(); } } catch (Exception e) { // e.printStackTrace(); throw new SecurityException(); } } var ptr = Open(Android.Runtime.JNIEnv.Handle, this.Handle, JNIEnv.NewString(device.AbsolutePath), baudrate, flags); if (ptr != System.IntPtr.Zero) { mFd = GetObject <FileDescriptor>(ptr, JniHandleOwnership.DoNotRegister); } if (mFd == null) { // Log.e(TAG, "native open returns null"); throw new IOException(); } mFileInputStream = new FileInputStream(mFd); mFileOutputStream = new FileOutputStream(mFd); }
/** * * Método faz a formatação do cartão. * * A formatação do cartão só é necessario na sua primeira gravação. * * Após já existir algum valor gravado no cartão, não será possível formata-lo * novamente. * * @param ndef = Contém as informações do cartão que esta sendo lido. * * @throws IOException * @throws FormatException * * @return boolean => True = Cartão Formatado / False = Cartão não formatado * * */ public bool FormataCartao(Ndef ndef) { bool retorno = false; NdefFormatable ndefFormatable = NdefFormatable.Get(ndef.Tag); Java.Lang.String msg = new Java.Lang.String(MENSAGEM_PADRAO); try { if (ndefFormatable == null) { return(retorno); } if (!ndefFormatable.IsConnected) { ndefFormatable.Connect(); } ndefFormatable.Format(new NdefMessage(NdefRecord.CreateMime ("UTF-8", msg.GetBytes(Charset.ForName("UTF-8"))))); ndefFormatable.Close(); retorno = true; } catch (IOException e) { throw new IOException(e.Message); } catch (System.FormatException e) { throw new System.FormatException(e.Message); } finally { this.GravaTempoFinal(); } return(retorno); }
private void writeData(Java.Lang.String data) { try { outStream = btSocket.OutputStream; } catch (System.Exception e) { Console.WriteLine("Error al enviar" + e.Message); } Java.Lang.String message = data; byte[] msgBuffer = message.GetBytes(); try { outStream.Write(msgBuffer, 0, msgBuffer.Length); } catch (System.Exception e) { Console.WriteLine("Error al enviar" + e.Message); } }
public static byte[] decode(string var0) { StringBuffer var1 = new StringBuffer(); Java.Lang.String var0Str = (Java.Lang.String)var0.ToString(); sbyte[] var2 = (sbyte[])(Array)var0Str.GetBytes("US-ASCII"); int var3 = var2.Length; int[] var4 = new int[] { 0 }; while (var4[0] < var3) { sbyte var5 = GetValue(var2, var3, var4); if (var5 == -1) { break; } sbyte var6 = GetValue(var2, var3, var4); if (var6 == -1) { break; } var1.Append((char)(var5 << 2 | (var6 & 48) >> 4)); sbyte var7; do { var7 = var2[var4[0]++]; if (var7 == 61) { Java.Lang.String var1Str = (Java.Lang.String)var1.ToString(); return(var1Str.GetBytes("iso8859-1")); } var7 = Base64DecodeChars[var7]; } while (var4[0] < var3 && var7 == -1); if (var7 == -1) { break; } var1.Append((char)((var6 & 15) << 4 | (var7 & 60) >> 2)); sbyte var8; do { var8 = var2[var4[0]++]; if (var8 == 61) { Java.Lang.String var1Str = (Java.Lang.String)var1.ToString(); return(var1Str.GetBytes("iso8859-1")); } var8 = Base64DecodeChars[var8]; } while (var4[0] < var3 && var8 == -1); if (var8 == -1) { break; } var1.Append((char)((var7 & 3) << 6 | var8)); } Java.Lang.String var1Strmain = (Java.Lang.String)var1.ToString(); return(var1Strmain.GetBytes("iso8859-1")); }