# Installed Apps Crashes using Processing 4.2 Android Mode

**URL:** <https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111>\
**Category:** Processing for Android\
**Created:** [May 30, 2023, 2:20pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111 "2023-05-30T14:20:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Myrdalm](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@Myrdalm](https://discourse.processing.org/u/Myrdalm)\
**Post date:** [May 30, 2023, 2:20pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/1 "2023-05-30T14:20:32Z")

</div>

Installing codes using processing 4.2, even if the given sample codes are successfully installed on the Android device/phone, crashes when I try running them. It worked before in processing 3, can’t find the issue. Any insights that you could share?

Thank you

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [May 30, 2023, 9:27pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/2 "2023-05-30T21:27:53Z")

</div>

Hi @Myrdalm,

Welcome to the forum! 😉

Without any information about your device / logs in the output window we can’t help you further with this!

Can you provide more debug material?

---

<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:** [May 30, 2023, 11:08pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/3 "2023-05-30T23:08:42Z")

</div>

Hi

> [@\[Android\] 'Text is garbled.' When will it be resolved? help me](https://discourse.processing.org/t/android-text-is-garbled-when-will-it-be-resolved-help-me/38969):
>
> ref link : [[Android] Regarding the Android mode, has the text breakage been resolved?](https://discourse.processing.org/t/android-regarding-the-android-mode-has-the-text-breakage-been-resolved/24139) Please refer to the image. example) Korean / Japanese / English If you experiment through, All texts are broken except in English. CharSequence[] Choice\_v = {"공급기-1","공급기-2","공급기-3","공급기-4","공급기-5","공급기-6"}; // Korean CharSequence[] Choice\_v = {"FEED-1","FEED-2","FEED-3","FEED-4","FEED-5","FEED-6"}; // English I’ve mentioned it before. 2-1) There is no ‘text break phen…

---

<div class="post-metadata">

**Author:** ![Myrdalm](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@Myrdalm](https://discourse.processing.org/u/Myrdalm)\
**Post date:** [May 31, 2023, 6:55am UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/4 "2023-05-31T06:55:36Z")

</div>

Hello,

I used the NoBackgroundTest code sample

void setup() {  
size(400, 400, P2D);  
background(255, 0, 0);  
fill(255, 150);  
}

void draw() {  
ellipse(mouseX, mouseY, 100, 100);  
}

And below is the output in the console:

Build folder: C:\Users\MMM\AppData\Local\Temp\android15489222564811472272sketch  
WARNING:We recommend using a newer Android Gradle plugin to use compileSdk = 33

This Android Gradle plugin (7.1.0) was tested up to compileSdk = 32

This warning can be suppressed by adding  
android.suppressUnsupportedCompileSdk=33  
to this project’s gradle.properties

The build will continue, but you are strongly encouraged to update your project to  
use a newer Android Gradle Plugin that has been tested with compileSdk = 33  
Observed package id ‘platforms;android-33-ext5’ in inconsistent location ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33’ (Expected ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33-ext5’)  
Observed package id ‘platforms;android-33’ in inconsistent location ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33-2’ (Expected ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33’)

> Task :app:preBuild UP-TO-DATE  
> Task :app:preDebugBuild UP-TO-DATE  
> Task :app:mergeDebugNativeDebugMetadata NO-SOURCE  
> Task :app:compileDebugAidl NO-SOURCE  
> Task :app:compileDebugRenderscript NO-SOURCE  
> Task :app:generateDebugBuildConfig  
> Task :app:javaPreCompileDebug  
> Task :app:generateDebugResValues  
> Task :app:generateDebugResources  
> Task :app:checkDebugAarMetadata  
> Task :app:createDebugCompatibleScreenManifests  
> Task :app:extractDeepLinksDebug  
> Task :app:mergeDebugResources  
> Task :app:processDebugMainManifest  
> Task :app:processDebugManifest  
> Task :app:mergeDebugShaders  
> Task :app:compileDebugShaders NO-SOURCE  
> Task :app:generateDebugAssets UP-TO-DATE  
> Task :app:mergeDebugAssets  
> Task :app:compressDebugAssets  
> Task :app:processDebugJavaRes NO-SOURCE  
> Task :app:checkDebugDuplicateClasses  
> Task :app:mergeDebugJavaResource  
> Task :app:mergeDebugJniLibFolders  
> Task :app:mergeDebugNativeLibs NO-SOURCE  
> Task :app:stripDebugDebugSymbols NO-SOURCE  
> Task :app:validateSigningDebug  
> Task :app:processDebugManifestForPackage  
> Task :app:writeDebugAppMetadata  
> Task :app:writeDebugSigningConfigVersions  
> Task :app:processDebugResources

> Task :app:compileDebugJavaWithJavac  
> Annotation processing got disabled, since it requires a 1.6 compliant JVM

> Task :app:dexBuilderDebug  
> Task :app:desugarDebugFileDependencies  
> Task :app:mergeExtDexDebug  
> Task :app:mergeDexDebug  
> Task :app:packageDebug  
> Task :app:createDebugApkListingFileRedirect  
> Task :app:assembleDebug

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use ‘–warning-mode all’ to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See [Command-Line Interface](https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings)

BUILD SUCCESSFUL in 37s  
27 actionable tasks: 27 executed

Though it is installed successfully, when I run the app, the app in the phone crashes, this only started when I started using processing which does not happen before when I used processing 3.

 ![350350876_265617795951330_3640855877575243864_n](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/d/8d138b5023eea8f89b4249ff89d48f8a01e43366.jpeg)

---

<div class="post-metadata">

**Author:** ![robertesler](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@robertesler](https://discourse.processing.org/u/robertesler)\
**Post date:** [May 31, 2023, 8:57pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/5 "2023-05-31T20:57:50Z")

</div>

Hi @Myrdalm.  
What version of Android is installed on your device? Which version of Android mode do you have installed with Processing?

Also use the Processing Android examples to be certain that isn’t the issue. Try:

```auto
void setup() {
  fullScreen();
  noStroke();
  fill(0);
}

void draw() {
  background(204);
  if (mousePressed) {
    if (mouseX < width/2) {
      rect(0, 0, width/2, height); // Left
    } else {
      rect(width/2, 0, width/2, height); // Right
    }
  }
}

```

Finally, check the Processing console print out for any other information. Usually it will provide information on what was the cause of the crash. If not there are apps for Android that print the crash logs. We need more info to figure out the issue.

---

<div class="post-metadata">

**Author:** ![Myrdalm](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@Myrdalm](https://discourse.processing.org/u/Myrdalm)\
**Post date:** [May 31, 2023, 10:08pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/6 "2023-05-31T22:08:42Z")

</div>

I am using the Android 11 Version on my device. I am using Android Mode 4.5.1. intstalled with Processing. SDK updater has also updated everything to all the latest versions.

The sample I used on my first test was from a Processing Android example.  
The code you used also had the same issue as the code I used earlier.

Processing console print is the same as before, copied and paste below:

Build folder: C:\Users\MMM\AppData\Local\Temp\android12071222152819130336sketch  
WARNING:We recommend using a newer Android Gradle plugin to use compileSdk = 33

This Android Gradle plugin (7.1.0) was tested up to compileSdk = 32

This warning can be suppressed by adding  
android.suppressUnsupportedCompileSdk=33  
to this project’s gradle.properties

The build will continue, but you are strongly encouraged to update your project to  
use a newer Android Gradle Plugin that has been tested with compileSdk = 33  
Observed package id ‘platforms;android-33-ext5’ in inconsistent location ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33’ (Expected ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33-ext5’)  
Observed package id ‘platforms;android-33’ in inconsistent location ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33-2’ (Expected ‘C:\Users\MMM\Documents\Processing\android\sdk\platforms\android-33’)

> Task :app:preBuild UP-TO-DATE  
> Task :app:preDebugBuild UP-TO-DATE  
> Task :app:mergeDebugNativeDebugMetadata NO-SOURCE  
> Task :app:compileDebugAidl NO-SOURCE  
> Task :app:compileDebugRenderscript NO-SOURCE  
> Task :app:generateDebugBuildConfig  
> Task :app:javaPreCompileDebug  
> Task :app:generateDebugResValues  
> Task :app:generateDebugResources  
> Task :app:checkDebugAarMetadata  
> Task :app:createDebugCompatibleScreenManifests  
> Task :app:extractDeepLinksDebug  
> Task :app:mergeDebugResources  
> Task :app:processDebugMainManifest  
> Task :app:processDebugManifest  
> Task :app:mergeDebugShaders  
> Task :app:compileDebugShaders NO-SOURCE  
> Task :app:generateDebugAssets UP-TO-DATE  
> Task :app:mergeDebugAssets  
> Task :app:compressDebugAssets  
> Task :app:processDebugJavaRes NO-SOURCE  
> Task :app:checkDebugDuplicateClasses  
> Task :app:mergeDebugJavaResource  
> Task :app:mergeDebugJniLibFolders  
> Task :app:mergeDebugNativeLibs NO-SOURCE  
> Task :app:stripDebugDebugSymbols NO-SOURCE  
> Task :app:validateSigningDebug  
> Task :app:writeDebugAppMetadata  
> Task :app:writeDebugSigningConfigVersions  
> Task :app:processDebugManifestForPackage  
> Task :app:processDebugResources

> Task :app:compileDebugJavaWithJavac  
> Annotation processing got disabled, since it requires a 1.6 compliant JVM

> Task :app:dexBuilderDebug  
> Task :app:desugarDebugFileDependencies  
> Task :app:mergeExtDexDebug  
> Task :app:mergeDexDebug  
> Task :app:packageDebug  
> Task :app:createDebugApkListingFileRedirect  
> Task :app:assembleDebug

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use ‘–warning-mode all’ to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See [Command-Line Interface](https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings)

BUILD SUCCESSFUL in 36s  
27 actionable tasks: 27 executed

After using and updating processing android 4 and returning to processing 3, processing 3 is also not working anymore.

---

<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:** [May 31, 2023, 11:58pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/7 "2023-05-31T23:58:00Z")

</div>

> [@Myrdalm](#):
>
> returning to processing 3, processing 3 is also not working anymore.

Hi this works with processing 3

> [@Export to exe file](https://discourse.processing.org/t/export-to-exe-file/23186/9):
>
> I don’t have problems with this at all. I just use [this SDK folder](https://drive.google.com/file/d/1JIMtod4Qxo8_ciJmZyfPKydyu0Xd6kDa/view) and unzip it in the documents/processing folder or elsewhere. Then open I the preferences.txt file. (The location you can find at the bottom of the File/settings menu.) In the android parameters you will find something like: android.emulator.image.abi=x86 android.emulator.port.phone=5566 android.sdk.ar=1.12.0 android.sdk.gvr=1.180.0 android.sdk.path=D:\an\android\sdk android.sdk.play\_services=16.0.1 android.sdk.support=28.0.0 a…

---

<div class="post-metadata">

**Author:** ![robertesler](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@robertesler](https://discourse.processing.org/u/robertesler)\
**Post date:** [June 1, 2023, 12:19am UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/8 "2023-06-01T00:19:53Z")

</div>

@Myrdalm,  
If you are not seeing any other errors than the only other thing I can think of is to try setting your target sdk to 31 in your AndroidManifest.xml or you could change your compile sdk to 31 but you would have to have that installed.  
It looks like you’re compiling for sdk 33, aka Android 13, which usually doesn’t break things when testing on lower versions. But that is the only thing I can see that is different.  
Otherwise there are Android apps that let you read the debug log and there may be more information there, but it doesn’t appear that you are doing anything “wrong.” So my guess is it is either the device itself or the sdk version.

---

<div class="post-metadata">

**Author:** ![Myrdalm](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@Myrdalm](https://discourse.processing.org/u/Myrdalm)\
**Post date:** [June 1, 2023, 7:14am UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/9 "2023-06-01T07:14:13Z")

</div>

I tried using processing 3, but now it is updated with processing for, it is not working anymore compared to before. Below is the SS when I use processing 3 now.

 ![342493221_685719969909223_6911726853347859757_n](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/a/9/a923b7ddb6d333c22f1593aaebe52cc5226c8ebb.png)

---

<div class="post-metadata">

**Author:** ![Myrdalm](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@Myrdalm](https://discourse.processing.org/u/Myrdalm)\
**Post date:** [June 1, 2023, 7:18am UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/10 "2023-06-01T07:18:58Z")

</div>

How do I set target sdk? I prefer using processing 4 though, due to the reason that it is the latest version.

Have you tried using processing 4 in Android 11, 12 and 13? If so, can you share what you experienced and did it worked?

I would appreciate it if you would be able to help me make it work instead of it crashing.

Thank you

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [June 1, 2023, 10:03am UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/11 "2023-06-01T10:03:27Z")

</div>

You can set the target sdk by editing the Preferences file. On a Windows 11 system it is located at C:/Users/yourName/AppData/Roaming/Processing/Preferences. However, when I try to change the value from 33 to 32, it just overwrites the file when I run the app the next time and sets it back to 33. The edit doesn’t ‘stick’; and yes, the Processing editor was closed when I made the change. I have an experience similar to yours and I run in Android mode on both Windows and Mac. The last update made it impossible for me to use the Windows OS for Processing Android apps. I got the Mac version to run after downloading a custom Android mode from github:[https://github.com/processing/processing-android/issues/729#issuecomment-1516919114](https://github.com/processing/processing-android/issues/729#issuecomment-1516919114)  
**Addendum:**  
I just replaced the Android mode file on my Windows system with the github file above and it is now fixed; Android runs as expected except for the Gradle warning (which I have yet to figure out how to fix). However, my issue may be different from the one you are experiencing.

---

<div class="post-metadata">

**Author:** ![robertesler](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@robertesler](https://discourse.processing.org/u/robertesler)\
**Post date:** [June 1, 2023, 4:29pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/12 "2023-06-01T16:29:27Z")

</div>

Hi @Myrdalm  
Yes, I’ve used the Android mode on devices from Android 10-13 using P4 on both Mac and Win10. I’ve used Samsung, Pixel and OnePlus devices. The only time I have had an app crash on startup is when it was accessing an API that wasn’t available. For example a new feature only available in Android 13 but not in my target build of Android 12.  
Short from updating to a new device, my only other recommendation is to revert to an older Android mode and Android Sdk install until it works. You would have to do this manually. It seems like the updated Android mode is breaking the build for your device.  
You could also try looking at the crash reports. Connect your device to your machine, using the Command Prompt or Terminal (adb needs to be added to your Environment Variables or shell commands):  
`adb logcat -b crash`  
and see what happens when you open the crashing app. There are also LogCat reader apps for Android devices.

---

<div class="post-metadata">

**Author:** ![Myrdalm](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@Myrdalm](https://discourse.processing.org/u/Myrdalm)\
**Post date:** [June 2, 2023, 9:48am UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/13 "2023-06-02T09:48:00Z")

</div>

I don’t have mac and I only use Windows 10, can’t afford to buy additional gadgets as of now. May I know where the Android mode folder can be found? Hope your solution can work, I’ve been struggling since I used processing 4.

Thank you

---

<div class="post-metadata">

**Author:** ![Myrdalm](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@Myrdalm](https://discourse.processing.org/u/Myrdalm)\
**Post date:** [June 2, 2023, 9:50am UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/14 "2023-06-02T09:50:03Z")

</div>

How do I add the adb to my Environment Variables, do I need to install something?

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [June 2, 2023, 1:03pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/15 "2023-06-02T13:03:18Z")

</div>

On my Windows system it’s in C:/Documents/Processing/modes. You might want to change the name of the original AndroidMode folder to something like AndroidMode\_orig, otherwise any new download will overwrite the old one. Hope it works for you.

---

<div class="post-metadata">

**Author:** ![Myrdalm](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@Myrdalm](https://discourse.processing.org/u/Myrdalm)\
**Post date:** [June 2, 2023, 2:51pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/17 "2023-06-02T14:51:01Z")

</div>

Your solution worked so far, it seems that the issue is in the **Android mode folder**. Though I will still try testing it with more complicated codes and update, here again, codes that involve Bluetooth if P4 affected it.

The solution so far is very helpful.

Thank you

---

<div class="post-metadata">

**Author:** ![Myrdalm](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@Myrdalm](https://discourse.processing.org/u/Myrdalm)\
**Post date:** [June 3, 2023, 8:07am UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/18 "2023-06-03T08:07:40Z")

</div>

I tried including bluetooth codes that used to work with processing 3, now it does not. If you could give me feedback or a solution, that would be great, but if not, maybe I should give up in using processing android, for everytime processing upgrades, problems always arise.

Here is the code incorporated with bluetooth codes:

```auto
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.widget.Toast;
import android.view.Gravity;
import android.bluetooth.BluetoothAdapter;
//import android.bluetooth.BluetoothManager; //added
import android.bluetooth.BluetoothDevice;
import java.util.UUID;
import android.os.Looper;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import android.app.Activity;

public BluetoothSocket scSocket;

boolean foundDevice=false;
boolean BTisConnected=false;
String serverName = "ArduinoBasicServer";

// ***For GUI Communicaion*** //
public static final int MESSAGE_WRITE = 1;
public static final int MESSAGE_READ = 2;
private static final int RESULT_OK = 1;
String readMessage="";
SendReceiveBytes sendReceiveBT = null;

// ***For Bluetooth Initialization*** //
@SuppressWarnings("deprecation")
BluetoothAdapter bluetooth = BluetoothAdapter.getDefaultAdapter();
//BluetoothManager bluetoothManager = (BluetoothManager)getActivity().getSystemService(Context.BLUETOOTH_SERVICE);
//BluetoothAdapter bluetooth = bluetoothManager.getAdapter();

// ***For Bluetooth Features*** //
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  if(requestCode==0) {
  if(resultCode==RESULT_OK) {
  background(0);
  ToastMaster ("Bluetooth has been switched ON");
  ToastMaster("Please Reload Application to Connect to Device");
  ToastMaster("Please Reload Application to Connect to Device");
  ToastMaster("Please Reload Application to Connect to Device");
  } else {
  background(0);
  ToastMaster("You need to turn Bluetooth ON !!!");
  ToastMaster("You need to turn Bluetooth ON !!!");
  ToastMaster("You need to turn Bluetooth ON !!!");
  }
  }
}

BroadcastReceiver myDiscoverer = new myOwnBroadcastReceiver();
BroadcastReceiver checkIsConnected = new myOwnBroadcastReceiver();

// ***For GUI Communication*** //
private final Handler mHandler = new Handler(Looper.getMainLooper()) {  
  @ Override
  public void handleMessage(Message msg) 
     {
  switch (msg.what) 
      {
  case MESSAGE_WRITE:
  break;
  case MESSAGE_READ:
  byte[] readBuf = (byte[]) msg.obj;
  readMessage = new String(readBuf, 0, msg.arg1);
  break;
    }
  }
};

// ***For GUI Setup*** //
void setup() {
  fullScreen();
  noStroke();
  fill(0);
 
// ***For Bluetooth Features*** // 
  if (!bluetooth.isEnabled()) {
  Intent requestBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
  this.getActivity().startActivityForResult(requestBluetooth, 0);
  }

  if (bluetooth.isEnabled()) {
  this.getActivity().registerReceiver(myDiscoverer, new IntentFilter(BluetoothDevice.ACTION_FOUND));
  this.getActivity().registerReceiver(checkIsConnected, new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED));

  if (!bluetooth.isDiscovering()) {
  bluetooth.startDiscovery();
  }
  }
}

// ***GUI Proper Design Setup*** //
void draw() {
  if(foundDevice) {
    if(BTisConnected){
      background(204);
      if(mousePressed){
        if (mouseX < width/2) {
          rect(0, 0, width/2, height); // Left
          byte[] myByte = stringToBytesUTFCustom("L");
          sendReceiveBT.write(myByte);
        } else {
          rect(width/2, 0, width/2, height); // Right
          byte[] myByte = stringToBytesUTFCustom("R");
          sendReceiveBT.write(myByte);
        }
      }
    }
  }
}
      
// ***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);
  //@SuppressWarnings("deprecation") // -- OLD
  //BluetoothDevice discoveredDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); -- Deprecaded Code
  BluetoothDevice discoveredDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE,BluetoothDevice.class);
  foundDevice=true;
  
  if(discoveredDeviceName.equals("HMSoft")) {
  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 onDestroy() {    
  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");
  }
  }

  @SuppressWarnings("unused")
  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();
}

```

Any help would be appreciated.

Thank you

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [June 3, 2023, 2:27pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/19 "2023-06-03T14:27:28Z")

</div>

The errors that I get when trying to run your Bluetooth code are primarily string errors. When I get time I will try to debug it for you. Your code will likely run when these are fixed; it does not appear to be a Processing problem. In the meantime, please see if you are able to run this demo; it’s what I use for Android bluetooth communication: [https://github.com/vsquared/Processing\_Android](https://github.com/vsquared/Processing_Android)

---

<div class="post-metadata">

**Author:** ![Myrdalm](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@Myrdalm](https://discourse.processing.org/u/Myrdalm)\
**Post date:** [June 3, 2023, 3:12pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/20 "2023-06-03T15:12:58Z")

</div>

Does it still have errors? It did not show errors in my end though. Looking forward for errors in my end.

Thank you

---

<div class="post-metadata">

**Author:** ![Myrdalm](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@Myrdalm](https://discourse.processing.org/u/Myrdalm)\
**Post date:** [June 3, 2023, 3:17pm UTC](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111/21 "2023-06-03T15:17:16Z")

</div>

Though those codes worked in processing 3 before.

[Next page](https://discourse.processing.org/t/installed-apps-crashes-using-processing-4-2-android-mode/42111.md?page=2)
