# APDE ketai example

**URL:** <https://discourse.processing.org/t/apde-ketai-example/27133>\
**Category:** Processing for Android\
**Created:** [January 17, 2021, 7:23am UTC](https://discourse.processing.org/t/apde-ketai-example/27133 "2021-01-17T07:23:10Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 17, 2021, 7:23am UTC](https://discourse.processing.org/t/apde-ketai-example/27133/1 "2021-01-17T07:23:10Z")

</div>

Hi this code receive data from terminal but not sending what I missed ?

```auto
import android.content.Intent;
import android.os.Bundle;
import ketai.net.bluetooth.*;
import ketai.ui.*;
import ketai.net.*;

PFont fontMy;
boolean bReleased = true; //no permament sending when finger is tap
KetaiBluetooth bt;
boolean isConfiguring = true;
String info = "";
KetaiList klist;
ArrayList devicesDiscovered = new ArrayList();

// ********************************************************************
// The following code is required to enable bluetooth at startup.
// ********************************************************************

void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 bt = new KetaiBluetooth(this);
}

void onActivityResult(int requestCode, int resultCode, Intent data) {
 bt.onActivityResult(requestCode, resultCode, data);
}

void setup() {
 size(displayWidth, displayHeight);
 frameRate(10);
 orientation(PORTRAIT);
 background(0);
 
 //start listening for BT connections
 bt.start();
 //at app start select device…
 isConfiguring = true;
 //font size
 fontMy = createFont("SansSerif", 40);
 textFont(fontMy);
}

void draw() {
 //at app start select device
 if (isConfiguring)
 {
  ArrayList names;
  background(78, 93, 75);
  klist = new KetaiList(this, bt.getPairedDeviceNames());
  isConfiguring = false;
 }
 else
 {
  background(0,50,0);
  if((mousePressed) && (bReleased == true))
  {
 //send with BT
  byte[] data = {'s','w','i','t','c','h','\r'};
  bt.broadcast(data);
 //first tap off to send next message
  bReleased = false;
  }
  if(mousePressed == false)
  {
  bReleased = true; //finger is up
  }
 //print received data
  fill(255);
  noStroke();
  textAlign(LEFT);
  text(info, 20, 104);
 }
}

void onKetaiListSelection(KetaiList klist) {
 String selection = klist.getSelection();
 bt.connectToDeviceByName(selection);
 //dispose of list for now
 klist = null;
}

//Call back method to manage data received
void onBluetoothDataEvent(String who, byte[] data) {
 if (isConfiguring)
 return;
 //received
 info += new String(data);
 //clean if string to long
 if(info.length() > 150)
 info = "";
}

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 17, 2021, 11:15am UTC](https://discourse.processing.org/t/apde-ketai-example/27133/2 "2021-01-17T11:15:31Z")

</div>

![Screenshot_2021-01-17-15-06-20-299](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a82b04c428a237f7ce2fcabe485393c914f6e269.jpeg)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [January 17, 2021, 11:23am UTC](https://discourse.processing.org/t/apde-ketai-example/27133/3 "2021-01-17T11:23:36Z")

</div>

Hi!

I read it so [it](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a82b04c428a237f7ce2fcabe485393c914f6e269.jpeg) must be working! `:)`

Thanks for updating original post with more details.

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 17, 2021, 11:26am UTC](https://discourse.processing.org/t/apde-ketai-example/27133/4 "2021-01-17T11:26:27Z")

</div>

hi

😀 😀

working one way just receiving

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [January 17, 2021, 11:48am UTC](https://discourse.processing.org/t/apde-ketai-example/27133/5 "2021-01-17T11:48:18Z")

</div>

Hello,

I tried your code with the Arduino serial monitor and it is sending and receiving.

When I touch Android screen the Arduino serial monitor receives “switch”.  
When I type in text and send it with the Arduino serial monitor I receive it on the Android display.

I find the Arduino monitor handy for quick testing… not as configurable as other [terminal emulators](https://en.wikipedia.org/wiki/List_of_terminal_emulators) but works!

`:)`

I sent this with Arduino serial monitor to Android:

 ![Screenshot_20210117-064535](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0aa60d951a3176de370116c5b7b327aedf985f35.png)

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 17, 2021, 11:56am UTC](https://discourse.processing.org/t/apde-ketai-example/27133/6 "2021-01-17T11:56:30Z")

</div>

thanks

when i did not receive on terminal i felt lazy to try other way

i am going to walk on your steps thanks for response

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [January 17, 2021, 12:03pm UTC](https://discourse.processing.org/t/apde-ketai-example/27133/7 "2021-01-17T12:03:45Z")

</div>

@jafal

I am not an expert with Android Processing…  
I mostly just come here to [dabble](https://www.lexico.com/definition/dabble) with and help others where I can.  
I enjoy the challenge.

Stay well!

`:)`

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [January 17, 2021, 12:12pm UTC](https://discourse.processing.org/t/apde-ketai-example/27133/8 "2021-01-17T12:12:10Z")

</div>

You are making special effort, may God bless you and thank you for your time
