Quantcast
Channel: Android Mode - Processing 2.x and 3.x Forum
Viewing all 941 articles
Browse latest View live

Overriding Volume Button : Android

$
0
0

Hello, I wanted to override the normal function of 'VOLUME_DOWN' keycode with my own thing. I am using this :

void keyPressed() { if( key == CODED && keyCode == android.view.KeyEvent.KEYCODE_VOLUME_DOWN ) { voldown(); \\my stuff } }

While doing this I am seeing that my function voldown() as well as normal android volume slider decrement is executing.


Can't get emulator to run a sketch, what do I do? (3.0)

$
0
0

New Processing user here, very excited to develop my app!

I got it to Run on Device but I'd also like to get the emulator working (especially since my colleagues will be using the emulator exclusively). I'm using Processing 3.0, fresh install of the latest Android Studio as well.

When I click Run in Emulator, the emulator boots up (eventually) and I checked and there's an entry for the Processing emulator in the AVD manager.

But when the console gets to "Debug..." and the little grey bar says "Sketch launched on the emulator", nothing has happened. The emulator is still blank (all black screen) and no phone OS even ever came up. (Btw the emulator window looks jenky—big grey half on the right with buttons—just to give you an idea which emulator window is showing up.)

What do I do to get this working?

Where to code on eclipse?

$
0
0

I exported my processing sketch to eclipse and runs good. Made some changes from the instructions I have readed and runs good in another button but runs. I have a list of folders at the left. I started clicking files to see if a file is where the code is. I do not know where the code is. Where do I start to code? I want to make changes to the sketch in Java.

FATAL EXCEPTION ; ANIMATION THREAD ; java.lang.NoSuchMethodError

$
0
0

hallo, i try to testing BluetoothCursors from example of library ketai . but i have some mistake

the code ist in this link

https://github.com/ketai/ketai/blob/master/examples/BluetoothCursors/BluetoothCursors.pde

i have this error :

Found onBluetoothDataEvent method. FATAL EXCEPTION: Animation Thread Process: processing.test.bluetoothcursors, PID: 17365 java.lang.NoSuchMethodError: processing.core.PApplet.getActivity at ketai.net.bluetooth.KetaiBluetooth.start(KetaiBluetooth.java:212) at processing.test.bluetoothcursors.BluetoothCursors.setup(BluetoothCursors.java:80) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source) at processing.core.PApplet.run(Unknown Source) at java.lang.Thread.run(Thread.java:841) Socket Type: SecureBEGIN mAcceptThreadThread[Thread-2495,5,main] AcceptThreadSecure

Thank you for helping

Beste Regards

USB Accessory with ArduinoADKUSb

$
0
0

Hallo, i want to test the library ArduinoAdkUsb , you can see here labs.arduino.cc/ADK/AccessoryMode.

But i habe processing 2.2.1 and its not work. then want to test this Libray with Arduino and Processing to read something. This Library work with procssing 2.0a4. i tried to dowland it, but there are no executable processing software.Can i have a new version of ArduinoAdkUb that i can use with processing 2.2.1

Thanks to help me

Can´t use some Android Methods

$
0
0

Hello,

I was developing an Android App for over 4 months and now im struck into a problem with some Methods since my old Processing version crashed.

I used some Android librarys to play sounds in my App but now it seems like Processing isnt able to find some Methods the Android SDK contains.

My Code to Play Sounds:

import android.media.MediaPlayer;
import android.content.res.*;

MediaPlayer player, player_1, player_2, player_3, player_4, player_5;
AssetManager assets;
AssetFileDescriptor fd;


void setup(){
  //Sounds
  player = new MediaPlayer();
  player_1 = new MediaPlayer();
  player_2 = new MediaPlayer();
  player_3 = new MediaPlayer();
  player_4 = new MediaPlayer();
  player_5 = new MediaPlayer();
  assets = this.getAssets();

  try {
    fd = assets.openFd("song.wav");
    player.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
    player.prepare();

    fd = assets.openFd("gameover.wav");
    player_1.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
    player_1.prepare();


    fd = assets.openFd("victory.wav");
    player_2.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
    player_2.prepare();

    fd = assets.openFd("arc.wav");
    player_3.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
    player_3.prepare();

    fd = assets.openFd("explosion.wav");
    player_4.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
    player_4.prepare();

    fd = assets.openFd("gamemusic.wav");
    player_5.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
    player_5.prepare();
  }
  catch (IOException e) {
    e.printStackTrace();
  }
  catch (IllegalArgumentException e) {
    e.printStackTrace();
  }
  catch (IllegalStateException e) {
    e.printStackTrace();
  }
}

In Processing 2.2.1 everything worked fine but after it crashed i had to install Android 3.0.1 to use Android Mode and now it seems like Processing had a Problem with the line " assets = this.getAssets();" as it reports :,, the function getAssets() does not exist" like it wasnt able to use some of the Android librarys. I tried to reinstall Processing and the Android Mode but nothing has changed. I know that the Error is not just about the sound, as im also not able to use other SDK Code to include e.g. Admob.

I’m working with API Level 6.0.

I hope someone can help me because I have no idea what I can do now to get it working again.

Thank You!!

Android sound and files

$
0
0

Is it going to be a sound library for an Android device? Or a library like PrintWriter as an equivalence to write data to a file on Android (like the score of a game)?

How I can fix this code for android

$
0
0

I found this code on the Internet, but has some errors and I could not correct. could help me I need it for a job. I'm using Processing 3.0.

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import java.util.ArrayList;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;

private static final int REQUEST_ENABLE_BT = 3;
ArrayList dispositivos;
BluetoothAdapter adaptador;
BluetoothDevice dispositivo;
BluetoothSocket socket;
InputStream ins;
OutputStream ons;
boolean registrado = false;
PFont f1;
PFont f2;
int estado;
String error;
byte valor;

BroadcastReceiver receptor = new BroadcastReceiver()
{
    public void onReceive(Context context, Intent intent)
    {
        println("onReceive");
        String accion = intent.getAction();

        if (BluetoothDevice.ACTION_FOUND.equals(accion))
        {
            BluetoothDevice dispositivo = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            println(dispositivo.getName() + " " + dispositivo.getAddress());
            dispositivos.add(dispositivo);
        }
        else if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(accion))
        {
          estado = 0;
          println("Empieza búsqueda");
        }
        else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(accion))
        {
          estado = 1;
          println("Termina búsqueda");
        }

    }
};

void setup() {
  //size(320,480);
  frameRate(25);
  f1 = createFont("Arial",20,true);
  f2 = createFont("Arial",15,true);
  stroke(255);
}

void draw() {
  switch(estado)
  {
    case 0:
      listaDispositivos("BUSCANDO DISPOSITIVOS", color(255, 0, 0));
      break;
    case 1:
      listaDispositivos("ELIJA DISPOSITIVO", color(0, 255, 0));
      break;
    case 2:
      conectaDispositivo();
      break;
    case 3:
      muestraDatos();
      break;
    case 4:
      muestraError();
      break;
  }
}

void onStart()
{
  super.onStart();
  println("onStart");
  adaptador = BluetoothAdapter.getDefaultAdapter();
  if (adaptador != null)
  {
    if (!adaptador.isEnabled())
    {
        Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
        startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
    }
    else
    {
      empieza();
    }
  }
}

void onStop()
{
  println("onStop");
  /*
  if(registrado)
  {
    unregisterReceiver(receptor);
  }
  */

  if(socket != null)
  {
    try
    {
      socket.close();
    }
    catch(IOException ex)
    {
      println(ex);
    }
  }
  super.onStop();
}

void onActivityResult (int requestCode, int resultCode, Intent data)
{
  println("onActivityResult");
  if(resultCode == RESULT_OK)
  {
    println("RESULT_OK");
    empieza();
  }
  else
  {
    println("RESULT_CANCELED");
    estado = 4;
    error = "No se ha activado el bluetooth";
  }
}

void mouseReleased()
{
  switch(estado)
  {
    case 0:
      /*
      if(registrado)
      {
        adaptador.cancelDiscovery();
      }
      */
      break;
    case 1:
      compruebaEleccion();
      break;
    case 3:
      compruebaBoton();
      break;
  }
}

void empieza()
{
    dispositivos = new ArrayList();
    for (BluetoothDevice dispositivo : adaptador.getBondedDevices())
    {
        dispositivos.add(dispositivo);
    }
    estado = 1;
}

void listaDispositivos(String texto, color c)
{
  background(0);
  textFont(f1);
  fill(c);
  text(texto,0, 20);
  if(dispositivos != null)
  {
    for(int indice = 0; indice < dispositivos.size(); indice++)
    {
      BluetoothDevice dispositivo = (BluetoothDevice) dispositivos.get(indice);
      fill(255,255,0);
      int posicion = 50 + (indice * 55);
      if(dispositivo.getName() != null)
      {
        text(dispositivo.getName(),0, posicion);
      }
      fill(180,180,255);
      text(dispositivo.getAddress(),0, posicion + 20);
      fill(255);
      line(0, posicion + 30, 319, posicion + 30);
    }
  }
}

void compruebaEleccion()
{
  int elegido = (mouseY - 50) / 55;
  if(elegido < dispositivos.size())
  {
    dispositivo = (BluetoothDevice) dispositivos.get(elegido);
    println(dispositivo.getName());
    estado = 2;
  }
}

void conectaDispositivo()
{
  try
  {
      Method m = dispositivo.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
      socket = (BluetoothSocket) m.invoke(dispositivo, 1);

    socket.connect();
    ins = socket.getInputStream();
    ons = socket.getOutputStream();
    estado = 3;
  }
  catch(Exception ex)
  {
    estado = 4;
    error = ex.toString();
    println(error);
  }
}

void muestraDatos()
{
  try
  {
    while(ins.available() > 0)
    {
      valor = (byte)ins.read();
    }
  }
  catch(Exception ex)
  {
    estado = 4;
    error = ex.toString();
    println(error);
  }
  background(0);
  fill(255);
  text(valor, width / 2, height / 2);
  stroke(255, 255, 0);
  fill(255, 0, 0);
  rect(120, 400, 80, 40);
  fill(255, 255, 0);
  text("Botón", 135, 425);
}

void compruebaBoton()
{
  if(mouseX > 120 && mouseX < 200 && mouseY > 400 && mouseY < 440)
  {
    try
    {
        ons.write(0);
    }
    catch(Exception ex)
    {
      estado = 4;
      error = ex.toString();
      println(error);
    }
  }
}

void muestraError()
{
  background(255, 0, 0);
  fill(255, 255, 0);
  textFont(f2);
  textAlign(CENTER);
  translate(width / 2, height / 2);
  rotate(3 * PI / 2);
  text(error, 0, 0);
}

How I can solve the following error

$
0
0

When you run the code I always get the following error but do not know how to correct it, someone could help me to correct the mistake it feels really appreciate it.

 void onActivityResult (int requestCode, int resultCode, Intent data)
    {
      println("onActivityResult");
      if(resultCode == RESULT_OK)
      {
        println("RESULT_OK");
        empieza();
      }
      else
      {
        println("RESULT_CANCELED");
        estado = 4;
        error = "No se ha activado el bluetooth";
      }
    }

Type safety: The method add(Object) belongs to the raw type ArrayList. References to generic type ArrayList should be parameterized

ERROR in C:\Users\EdwinS\AppData\Local\Temp\android59495307357018156sketch\src\processing\test\sketch_151101a\sketch_151101a.java (at line 162) if(resultCode == RESULT_OK) ^^^^^^^^^

Can not see Android Mode in "Add Mode", LINUX - debian

$
0
0

1 2 3

Think I have installed everything that is needed. Sorry for my english.. please, help.

Modify onBluetoothDataEvent() function execution?

$
0
0

Hi!! Actually, I'm working with communication between a GY-80 IMU and Android APP via Bluetooth. The communication its correct, using 115200 bauds in the two bluetooth. The problem it's when I'm using the onBluetoothDataEvent() function to read data of the bluetooth, the string return me a lot of lines of the Arduino port serial .

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

void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

bt = new KetaiBluetooth(this);

}

void onActivityResult(int requestCode, int resultCode, Intent data) {

bt.onActivityResult(requestCode, resultCode, data); contador+=1;

}

void setup() {

    bt.start();

    bt.getPairedDeviceNames();

    bt.connectToDeviceByName("HC-06");

} //Function to take bytes data from bluetooth this function is executed 1 time every 0.1 seconds

void onBluetoothDataEvent(String who, byte[] data) {

//Transform data to string

 info = new String(data); //

}

Investigating, I saw that the function it's executed 10 times in 1 second, and this cause to accumulate data on the temporal string variable "info", because Arduino it's sending 100 times per secon (0.01 delay), and the function onBluetoothDataEvent() it's reading bytes variable at 1 time every 0,1 second (checked with a simple counter inside the function). Using other App of Android, I received 1:1 transmissions and data view, discarding to be a problem bluetooth mobile.

Any possibility to change the execution of the function onBluetoothDataEvent() to read at real time bluetooth data?

Thanks and sorry for my poor English!

Fatal Exception with APWidgets

$
0
0

I'm trying to use APWidgets for some basic Android buttons, but creating an APWidgetContainer throws the error:

FATAL EXCEPTION: Animation Thread Process: processing.test.experiment, PID: 12094 java.lang.NoSuchMethodError: processing.core.PApplet.runOnUiThread

Is this an issue with the APWidget library?

Sony Experia Z3 to mac osx "no connected device"

$
0
0

Hello community,

I try to run a processing 3.0.1 sketch (android mode) on a device (sony experia Z3). But if I want to select a device its said "no connected device". But I connect the device with USB to my computer. Any ideas what the problem is?

greetings, Falk

How can i use switch(mouseButton) in android mode?

$
0
0

Hi, this is the part of my code that works on java mode, but obviously it doesn't work in android mode, so my question is, can i use this kind of switch on my android project? How can i make this work? I tried to change the mouse button with mouse pressed but i understood that i cannot use a boolean in a switch. This is the error that occurs every time (5 equals errors):


  1. ERROR in /private/var/folders/7h/__943dks5895p0qs_txz9p700000gn/T/android1454252317288703044sketch/src/processing/test/catchme/CatchMe.java (at line 101) switch(mouseButton) { ^^^^^^^^^^^

mouseButton cannot be resolved to a variable

This is the part of code of the first error:


void draw(){ // state if(mousePressed){ if(state == stateMenu){ if (rectOver) { switch(mouseButton) { case LEFT: state = statePlay; break; case RIGHT: state =stateLost; break; case ESC: // quit exit(); break; default: // do nothing break; } } }

}

How do i get sound to play on the phone

$
0
0

The code below works fine in java mode, but it doesn't work in Android mode. I just want a simple code that will play a mp3 file when clicked. I'm pretty sure the problem is in the import of Minim, I'm guessing it doesn't work for Android. If that is the case what do I need to use?

import ddf.minim.*; AudioPlayer player; Minim minim;
void setup(){minim = new Minim(this);} void draw(){} void mousePressed() { player = minim.loadFile("sin1.mp3" ); player.play(); } void stop() { player.close(); minim.stop(); super.stop(); }


A problem with performance using AudioRecord class

$
0
0

Greetings! In fact it is not a real problem, but i need some explanations about the reason causing that issue. So, i was making some simple dictaphone for my android device with a realtime waveform drawing. When i initialize AudioRecord object using stereo channels it's working fine, i got ~30 fps. But when i'm trying to use mono regime my fps falls to 12-15. Here is some code:

constants i'm using:

final int RECORDER_SAMPLERATE = 44100;
final int RECORDER_CHANNELS = AudioFormat.CHANNEL_IN_STEREO;
final int RECORDER_AUDIO_ENCODING = AudioFormat.ENCODING_PCM_16BIT;

recorder initializing:

bufferSize = AudioRecord.getMinBufferSize(RECORDER_SAMPLERATE,RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING);
audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
                            RECORDER_SAMPLERATE, RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING, bufferSize);

drawing waveform:

bufferReadResult = audioRecord.read(buffer, 0, inShorts);
x = 0;
    for(int i = 0; i < buffer.length; i += inc){
        newY = height/2 + (int)map(buffer[i], -40000,40000, -300,300);
        newX = x+1;
        line(x,y,newX, newY);
        x = newX;
        y = newY;
    }

inShorts it's just bufferSize/2 cause i'm using short arrays. In fact, i should divide mybuffer array in two arrays for each channel, but here where the problem is. When i'm trying to draw a single channel or use AudioFormat.CHANNEL_IN_MONO instead of stereo, i've got very low performance. The question is: why it is so? I checked that my microphone is a mono device.

How can you take a screenshot?

$
0
0

I have created an android game where I want the user to be able to share his score on twitter when he/she presses a button. I want the screenshot to be captured when the button is pressed. Please help. I am new to processing.

How to play OGG file with SoundPool?

$
0
0

I need to run my sounds and music (OGG files) on my phone but the code (a book's code to play it on android studio) does not run on my phone (it runs but says unfortunately stops on the phone). I am using eclipse luna I found on the web. I also import libraries I think I am using but I do not really know much of them. This is the similar code (so I hide real names and specify on sound):

    package processing.test.something;
    import processing.core.*;
    import processing.data.*;
    import processing.event.*;
    import processing.opengl.*;

    import java.util.HashMap;
    import java.util.ArrayList;
    import java.io.File;
    import java.io.BufferedReader;
    import java.io.PrintWriter;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.io.IOException;

    // Added imports I thought were usefull here
    import android.media.AudioManager;
    import android.media.SoundPool;
    import android.content.Context;
    import android.content.res.AssetFileDescriptor;
    import android.content.res.AssetManager;

    public class something extends PApplet {
    private SoundPool soundPool;
    int song = -1;
    void setup() {
    soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
    try {
    AssetManager assetManager = getAssets(); //I clicked generate method because getAssets() was labeled as an error.
    AssetFileDescriptor descriptor;
    descriptor = assetManager.openFd("song.ogg");
    song = soundPool.load(descriptor, 0);
    } catch (IOException e) {
    }
    soundPool.play(song, 1, 1, 0, 0, 1);
    } // End of setup()
    private AssetManager getAssets() {
        // TODO Auto-generated method stub
        return null;
    }
void draw() {
}
} // End class something

The console does not print errors. I do not know if it is a type of sketch permission or I am making something incomplete. How can I fix this code?

Trouble with the SelectFile library (Android mode)

$
0
0

When running the SelectFile library example I get a Fatal Exception error. Can someone explain me why? Thanks.

import select.files.*;

SelectLibrary files;

void setup() { size(320, 240);

files = new SelectLibrary(this);

files.selectInput("Select a file to process:", "fileSelected"); // files.selectFolder("Select a folder to process:", "fileSelected"); // files.selectOutput("Save the file please:", "fileSelected"); }

void fileSelected(File selection) { if (selection == null) { println("Nothing was selected."); } else { println("User selected " + selection.getAbsolutePath()); } }

FATAL EXCEPTION: Animation Thread Process: processing.test.sketch_151112c, PID: 1588 java.lang.NoSuchMethodError: processing.core.PApplet.runOnUiThread at select.files.SelectLibrary.selectImpl(Unknown Source) at select.files.SelectLibrary.selectInput(Unknown Source) at processing.test.sketch_151112c.sketch_151112c.setup(sketch_151112c.java:30) at processing.core.PApplet.handleDraw(Unknown Source) at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source) at processing.core.PApplet.run(Unknown Source) at java.lang.Thread.run(Thread.java:841)

Change keitai library baud rate

$
0
0

Found the solution. Didnt know how to delete post.

thanks!

Viewing all 941 articles
Browse latest View live