Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

  • Issue using Blepdroid (BluetoothLibrary) with Processing 3.3.7 and 3.4 earlier version 3.2.3 works

    This question is regarding a fatal exception error message that occurs when using Blepdroid (a Bluetooth low energy library) with later versions of Processing 3. The error has been partially addressed in an earlier question from other users experiencing the same problem. The previous answer while very useful does not solve the fundamental issue which my tests suggest may be a bug or unlisted change in Processing. I would value an opinion on the source of the problem before submitting it as a bug to the Processing developers. The error message is listed below.

    FATAL EXCEPTION: Animation Thread Process: processing.test.test2, PID: 17735 java.lang.NoSuchMethodError: No virtual method getFragmentManager()Landroid/app/FragmentManager; in class Lprocessing/core/PApplet; or its super classes (declaration of 'processing.core.PApplet' appears in /data/app/processing.test.test2-1/base.apk) at blepdroid.Blepdroid.(Blepdroid.java:293) at processing.test.test2.Test2.setup(Test2.java:88) at processing.core.PApplet.handleDraw(PApplet.java:1801) at processing.core.PSurfaceNone.callDraw(PSurfaceNone.java:471) at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:503)

    I've written many programs using Blepdroid and Processing version 3.2.3. These have worked perfectly for the last year, successfully accessing Blepdroid and presumably the fragment manager method that Blepdroid calls. However, with Processing version 3.3.7 and 3.4 my same programs plus Blepdroid still build successfully but when run they give the fatal exception error message shown above:

    My programs also continue to run properly with newly installed versions of the SDK for 3.2.3 provided I include my old Processing folder with its SDK folder. If I don't include the folder I get a message saying that Android no longer supports this version of Processing.

    Blepdroid hasn’t changed in the last year and I have been using the same copy of Bepdroid in that time. If Blepdroid has successfully called for FragmentManager in earlier versions then it must have been available in earlier versions. However, I couldn't find anything in the changes notes for Processing 3 that says access to the FragmentManager method has been changed?

    Before I raise this as a possible Bug in Processing can anyone suggest whether the problem is more likely to be with Processing or alternatively that the problem is the need for an update in Blepdroid to match changes in Processing?

    Thanks for any advice, Peter

  • APDE Tabs order

    I noticed that I can use even functions like setup() and draw() and event driven functions like mouse or bluetooth functions in random order. But this seems not to be true for java lifecycle functions like onCreate onStrart untill onStop. They must be on top of the sketch. Is that correct?

    PS For those working with APDE, as a temporary solution I found that if you transfer your sketch file to a desktop and rename it, than transfer back again; the tabs will be in alphabetic order.

  • Send/Recieve files

    i want to send the OktoberfestVSGermanElections.csv file, when i push the button(Message).This is my code bellow:

        import ketai.net.*;
        import ketai.net.bluetooth.*;
        import ketai.net.nfc.*;
        import ketai.net.nfc.record.*;
        import ketai.net.wifidirect.*;
        import ketai.sensors.*;
        import ketai.ui.*;
    
        import oscP5.*;
        import netP5.*;
        import grafica.*;
    
    
        OscP5 oscP5;
        NetAddress remoteLocation;
    
        double longitude, latitude, altitude;
        KetaiLocation location;
    
        Button on_button;  // the button
        int clk = 1;  
    
    
        String[] monthNames = new String[] {"January", "February", "March", "April", "May", "June", "July", 
                                             "August", "September", "October", "November", "December"};
        int[] daysPerMonth = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int[] daysPerMonthLeapYear = new int[] {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    
        GPlot plot;
    
        void setup() {
          fullScreen();
          //size(800, 410);
          orientation(LANDSCAPE);
          textAlign(CENTER, CENTER);
        textSize(22);
    
         location = new KetaiLocation(this);
    
        oscP5 = new OscP5(this,19000);
           on_button = new Button("Message", 850, 360, 150, 100);
        remoteLocation = new NetAddress("192.168.1.2",19000);
    
          // Load the Oktoberfest vs. Bundestagswahl (German elections day) Google 
          // search history file (obtained from the Google trends page). 
          // The csv file has the following format: 
          // year,month,day,oktoberfest,bundestagswahl
          // 2004,0,1,5,1
          // ...
          Table table = loadTable("OktoberfestVSGermanElections.csv", "header");
          table.setColumnType("year", Table.INT);
          table.setColumnType("month", Table.INT);
          table.setColumnType("day", Table.INT);
          table.setColumnType("oktoberfest", Table.INT);
          table.setColumnType("bundestagswahl", Table.INT);
    
          // Save the data in two GPointsArrays
          GPointsArray pointsOktoberfest = new GPointsArray();
          GPointsArray pointsElections = new GPointsArray();
    
          for (int row = 0; row < table.getRowCount(); row++) {
            int year = table.getInt(row, "year");
            int month = table.getInt(row, "month");
            int day = table.getInt(row, "day");
            float date = getExactDate(year, month, day);
            int oktoberfestCount = table.getInt(row, "oktoberfest");
            int electionsCount = table.getInt(row, "bundestagswahl");
    
            pointsOktoberfest.add(date, oktoberfestCount, monthNames[month]);
            pointsElections.add(date, electionsCount, monthNames[month]);
          }
    
          // Create the plot
          plot = new GPlot(this);
          plot.setDim(700, 300);
          plot.setTitleText("Oktoberfest vs. Bundestagwahl Google search history");
          plot.getXAxis().setAxisLabelText("Year");
          plot.getYAxis().setAxisLabelText("Google normalized searches");
          plot.getXAxis().setNTicks(10);
          plot.setPoints(pointsOktoberfest);
          plot.setLineColor(color(100, 100, 100));
          plot.addLayer("German elections day", pointsElections);
          plot.getLayer("German elections day").setLineColor(color(255, 100, 255));
          plot.activatePointLabels();
        }
    
        void draw() {
          background(255);
          on_button.Draw();
          if (location.getProvider() == "none")
            text("Location data is unavailable. \n" +
              "Please check your location settings.", -100,100, width, height);
          else
            text("Latitude: " + latitude + "\n" + 
              "Longitude: " + longitude + "\n" + 
              "Altitude: " + altitude + "\n" + 
              "Provider: " + location.getProvider(),  -100, 100, width, height);  
    
          // Draw the plot  
          plot.beginDraw();
          plot.drawBox();
          plot.drawXAxis();
          plot.drawYAxis();
          plot.drawTitle();
          plot.drawGridLines(GPlot.VERTICAL);
          plot.drawFilledContours(GPlot.HORIZONTAL, 0);
          plot.drawLegend(new String[] {"Oktoberfest", "Bundestagswahl"}, new float[] {0.07, 0.22}, 
                          new float[] {0.92, 0.92});
          plot.drawLabels();
          plot.endDraw();
        }  
    
    
        // Not really the exact date, but it's ok for this example
        float getExactDate(int year, int month, int day) {
          boolean leapYear = false;
    
          if (year % 400 == 0) {
            leapYear = true;
          }
          else if (year % 100 == 0) {
            leapYear = false;
          }
          else if (year % 4 == 0) {
            leapYear = true;
          }
    
          if (leapYear) {
            return year + (month + (day - 1f)/daysPerMonthLeapYear[month])/12f;
          }
          else {
            return year + (month + (day - 1f)/daysPerMonth[month])/12f;
          }
        }
    
        void mousePressed() {
          if (on_button.MouseIsOver()) {
          /* in the following different ways of creating osc messages are shown by example */
          OscMessage myMessage = new OscMessage("The Data are bellow:" +"\n" +
                       "Latitude: " + latitude + "\n" + 
              "Longitude: " + longitude + "\n" + 
              "Altitude: " + altitude);
    
          //myMessage.add(123); /* add an int to the osc message */
    
          /* send the message */
          oscP5.send(myMessage, remoteLocation); 
          }
        }
    
    
        void oscEvent(OscMessage theOscMessage) {
          /* print the address pattern and the typetag of the received OscMessage */
          print("### received an osc message.");
          print("Hello: "+theOscMessage.addrPattern());
         // println(" typetag: "+theOscMessage.typetag());
    
        }
        void onLocationEvent(double _latitude, double _longitude, double _altitude)
        {
          longitude = _longitude;
          latitude = _latitude;
          altitude = _altitude;
          println("lat/lon/alt: " + latitude + "/" + longitude + "/" + altitude);
        }
    
        class Button {
          String label; // button label
          float x;      // top left corner x position
          float y;      // top left corner y position
          float w;      // width of button
          float h;      // height of button
    
          // constructor
          Button(String labelB, float xpos, float ypos, float widthB, float heightB) {
            label = labelB;
            x = xpos;
            y = ypos;
            w = widthB;
            h = heightB;
          }
    
          void Draw() {
            fill(150);
            stroke(141);
            rect(x, y, w, h, 10);
            textAlign(CENTER, CENTER);
            fill(0);
            text(label, x + (w / 2), y + (h / 2));
          }
    
          boolean MouseIsOver() {
            if (mouseX > x && mouseX < (x + w) && mouseY > y && mouseY < (y + h)) {
              return true;
            }
            return false;
          }
        }
    
  • Closing app on Backpress using Android Processing

    Just to inform you, package on processing 3.3.7 is recognized as an error so I could not use the Keycode you sent me.

    But based on your inputs, with research and experimentation, indicated are the following details. (Please correct me if I am wrong).

    (1) I needed to use the System.exit(0); due to the reason that it is the only tested way I used to disconnect the target device with the app via bluetooth. When I don't use the indicated code, the app disconnects with the process but target device does not disconnect, creating an inefficiency in accessing app when placed on the background, which only happens when the back button is pressed.

    (2) onBackPressed(); onHomePressed(); is not read in processing 3.3.7. I think that the reason to this is that, onBackPressed and onHomePressed runs in an activity and not in a fragment. And P3.3.7 executes commands in a fragment

    (2) onStop(); onPause(); are affected by all buttons, that is why running System.exit(0); affected all buttons making all of the them disconnect application with the target device.

    (3)onStop(); onPause(); when used in running System.exit(0); affects the app background button, giving it a minor inefficiency, wherein when the button is pressed if it is the only app on the background, there is a situation wherein you need to re-access the application twice.

    (4) Based on my observation, pressing the backbutton destroys the app before it places it on the background, making the application disconnect without making the target device disconnect bluetooth connection. So due to this instead on focusing codes using onBackpress();, I used on onDestroy(); because it is not affect by the app backround button and homebutton. So applying system.exit(0); onDestroy, is just like executing the exit upon back button press.

    So tested and finalized, due to the reason that the application has no more issues when pressing the 3 buttons, I used the indicated code below in exchange for the code that I used in this thread.

    public void onDestroy(){ System.exit(0); }

    These is a shared effort, so I will just indicate it as answered from akenaton's last response. Thank you.

  • Closing app on Backpress using Android Processing

    I've just finished doing test doing "public void onPause, onStop, onResume and onStart" and also considered using "this.getActivity()" and System.exit(0);".

    The result are the following:

    (1) Based on the test, using "onPause" and "onStop" works. Also "System.exit(0);" should be used. It disconnects the bluetooth connection of both the application and the target device.

    (2) It keeps the application in the background and reconnects bluetooth connection with target paired device when re-accessed.

    But there is only one issue. When accessing app in the background, when displayed using the background applications button, the application does not respond on the first tap and displays or opens a different app. But reconnects on the second tap when app is re-accessed again.

    No major issue though, but unable to access the application on the first tap is not a good quality. The issue only arises when the background application is pressed, but no issues with the home and back button.

  • Closing app on Backpress using Android Processing

    I've been doing tests, and I thought of a solution. Indicated are the following observations.

    (1)Pressing the "background apps button" and the "home button" places the application on the background without disconnecting the bluetooth connection with the target device.

    (2)Pressing the "back button" places the application on the background disconnecting the bluetooth connection with the target device. A function placing the application onPause.

    The problem occurs when the back button is pressed due to the reason that the app disconnects the bluetooth but the target device does not disconnect its connection unless the app completely closes, which only can be done manually when accessing the application on the "backround applications" and closing it there.

    To efficiently reconnect the bluetooth connection of the app and the target device, the application should be completely closed, to also disconnect the bluetooth with the target device, but unfortunately, it is not possible. This makes "System.exit(0);" and "this.getActivity().finish();" not applicable. Also I tried removing the onBackpressed codes, and it works on (1) and (2) on default.

    Is there a way to do the other way around since it works on (1) and (2) on default. That onBackpressed, we avoid the application from disconnecting bluetooth connection?

    The truth is I already done everything I could, and I already want to give up. The only option that is left is how would I be able to work on the Bakpress button wothout disconnecting the bluetooth connection like the onPause.

  • Closing app on Backpress using Android Processing

    I forgot how to put the codes, but the issues started on the indicated codes, for there were a lot of changes done after changing codes to adapt for P3. I am not hoping much for a solution anymore, but just in case, you would see the error.

    // *** For Bluetooth Features *** // public class myOwnBroadcastReceiver extends BroadcastReceiver { ConnectToBluetooth connectBT;

    @Override public void onReceive(Context context, Intent intent) { String action=intent.getAction();

    if(BluetoothDevice.ACTION_FOUND.equals(action)){ String discoveredDeviceName = intent.getStringExtra(BluetoothDevice.EXTRA_NAME); BluetoothDevice discoveredDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); foundDevice=true;

    if(discoveredDeviceName.equals("HMSoft")) {//name of device ToastMaster("Connecting you Now !!!"); connectBT = new ConnectToBluetooth(discoveredDevice); new Thread(connectBT).start();

    } else { ToastMaster("Please Turn on Target Device"); ToastMaster("Please Turn on Target Device"); ToastMaster("Please Turn on Target Device"); ToastMaster("Please Turn on Target Device"); ToastMaster("Please Turn on Target Device"); } }

    if(BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)){ ToastMaster("Already CONNECTED with Target Device"); while(scSocket==null){ } BTisConnected=true; if(scSocket!=null){ sendReceiveBT = new SendReceiveBytes(scSocket); new Thread(sendReceiveBT).start(); String red = "r"; byte[] myByte = stringToBytesUTFCustom(red); sendReceiveBT.write(myByte); } } } }

    // *** for Communication *** // public static byte[] stringToBytesUTFCustom(String str) { char[] buffer = str.toCharArray(); byte[] b = new byte [buffer.length << 1]; for (int i = 0; i < buffer.length; i++) { int bpos = i << 1; b[bpos] = (byte) ((buffer[i]&0xFF00)>>8); b[bpos + 1] =(byte) (buffer[i]&0x00FF); } return b; }

    ////////////////////////////////////////////////////////////////////////////////////////////// public void onBackPressed() { System.exit(0); } ////////////////////////////////////////////////////////////////////////////////////////////

    public class ConnectToBluetooth implements Runnable{ private BluetoothDevice btShield; private BluetoothSocket mySocket = null; private UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

    public ConnectToBluetooth(BluetoothDevice bluetoothShield) { btShield = bluetoothShield;

    try{ mySocket = btShield.createRfcommSocketToServiceRecord(uuid); } catch(IOException createSocketException){ Log.e("ConnectToBluetooth", "Error with Socket"); } }

    public void run() { bluetooth.cancelDiscovery();

    try{ mySocket.connect(); scSocket=mySocket; } catch (IOException connectException){ Log.e("ConnectToBluetooth", "Error with Socket Connection");

    try{ mySocket.close(); } catch(IOException closeException){ } return; } }

    public BluetoothSocket getSocket() { return mySocket; }

    public void cancel() { try { mySocket.close(); } catch (IOException e) { } } }

    // *** For GUI Communication *** // private class SendReceiveBytes implements Runnable { private BluetoothSocket btSocket; private InputStream btInputStream = null; private OutputStream btOutputStream = null; String TAG = "SendReceiveBytes"; public SendReceiveBytes(BluetoothSocket socket) { btSocket = socket; try { btInputStream = btSocket.getInputStream(); btOutputStream = btSocket.getOutputStream(); } catch (IOException streamError) { Log.e (TAG, "Error when getting input or output Stream"); } }

    public void run () { byte[] buffer = new byte [1024]; int bytes; while (true) { try { bytes = btInputStream.read(buffer); mHandler.obtainMessage (MESSAGE_READ, bytes, -1, buffer) .sendToTarget(); } catch (IOException e) { Log.e(TAG, "Error reading from btInputStream"); break; } } }

    public void write(byte[] bytes) {
    try { btOutputStream.write(bytes); } catch (IOException e) { Log.e(TAG, "Error when writing to btOutputStream"); } }

    public void cancel() { try { btSocket.close(); } catch (IOException e) { Log.e(TAG, "Error when closing the btSocket"); } } }

    void ToastMaster(String textToDisplay) { Toast myMessage = Toast.makeText(this.getActivity().getApplicationContext(), textToDisplay, Toast.LENGTH_LONG); myMessage.setGravity(Gravity.CENTER, 0, 0); myMessage.show(); }

  • Closing app on Backpress using Android Processing

    @myrds===

    can you peut the code you are using now? - In order to be sure: everything is ok except that you want that when the back button is fired by the user bluetooth receiver continues to run?

  • Closing app on Backpress using Android Processing

    @myrds===

    • i cannot seen any reason why back button could disable bluetooth "in the system" (and home button will not)

    • it s impossible to "close completely" (i.e "quit") with android; for that you have to uninstall the app. Only the system can destroy an app (for memory reasons or others)

    • put your complete code as it is now (and dont forget onPause, on stop() && on resume())

    • there is no way to change the back button to home button: it does its job: back in the stack.

  • Closing app on Backpress using Android Processing

    My coding is the same when we fixed the P2 codes for P3 codes, I already tested the codes that you gave me and it seems that I already know what the problem is.

    When pressing the home button, the app does not disconnect the bluetooth connection that is why it runs the application in the background efficiently.

    While the Back button when pressed, disconnects the bluetooth in the system without having the paired device being disconnected, creating the Issue.

    Is there a way that in pressing backpress button will not disconnect the bluetooth from the system?

  • Closing app on Backpress using Android Processing

    @myrds===

    without knowing how you have created your blueTooth conn. it's difficult to answer...Yet, supposing that you have a broadcastReceiver running (called eg myDiscoverer) you have to code something like that::

          public void onPause(){
                    super.onPause();
    
                    if(myDiscoverer !=null){
                    getActivity().unregisterReceiver(myDiscoverer);
                    println("je désenregistre");
                    myDiscoverer=null;
                    }else{
                      println("désenregistré");
                    }
    
                    }
    
  • Closing app on Backpress using Android Processing

    @myrds===

    ok, now i understand; in this case, yes, its easy, you have to disconnect bluetooth in the onPause() method.

  • Closing app on Backpress using Android Processing

    Is there a code to disconnect bluetooth on backpress temporarily. Maybe this could work.

  • [Argument / Android mode] Processing Android Mode How to succeed

    @SnailPropulsionLabs===

    sorry, i have not seen any examples (from your link) related to wifi, blueTooh or nfc; tell me if i am wrong.

    @Gwak===

  • [Argument / Android mode] Processing Android Mode How to succeed

    @SnailPropulsionLabs

    I want Example code. 1) WIFI Communication 2) Bluetooth 3) NFC

  • bluetooth on android mode

    @robotman2412, @kfrajer=== i have tested the code i have put: it works for bluetooth; i cannot say for the arduino part.

  • bluetooth on android mode

    @robotman2412====

    see here: https://forum.processing.org/two/discussion/20881/processing-android-mode-android-device-bluetooth-arduino/p1

    my code is somewhere in the middle of the posts; code posted at the beginning by the guy who asked is not for P5 3XXX or 4 but for 2