import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.widget.TextView; import android.widget.EditText; import android.widget.Button; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Set; import java.util.UUID; public class MainActivity extends Activity { TextView myLabel; EditText myTextbox; BluetoothAdapter mBluetoothAdapter; BluetoothSocket mmSocket; BluetoothDevice mmDevice; OutputStream mmOutputStream; InputStream mmInputStream; Thread workerThread; byte[] readBuffer; int readBufferPosition; int counter; volatile boolean stopWorker; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myLabel = (TextView)findViewById(R.id.label); myTextbox = (EditText)findViewById(R.id.entry); //Open Button { { try { findBT(); openBT(); } } }); //Send Button { @Override { try { sendData(); } } }); //Close button { { try { closeBT(); } } }); } void findBT() { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if(mBluetoothAdapter == null) { myLabel.setText("No bluetooth adapter available"); } if(!mBluetoothAdapter.isEnabled()) { Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBluetooth, 0); } Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); if(pairedDevices.size() > 0) { for(BluetoothDevice device : pairedDevices) { { myLabel.setText(device.getName()); mmDevice = device; break; } } } } { UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); //Standard SerialPortService ID mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid); mmSocket.connect(); mmOutputStream = mmSocket.getOutputStream(); mmInputStream = mmSocket.getInputStream(); beginListenForData(); myLabel.setText("Bluetooth Opened"); } void beginListenForData() { final Handler handler = new Handler(); final byte delimiter = 10; //This is the ASCII code for a newline character stopWorker = false; readBufferPosition = 0; readBuffer = new byte[1024]; { public void run() { { try { int bytesAvailable = mmInputStream.available(); if(bytesAvailable > 0) { byte[] packetBytes = new byte[bytesAvailable]; mmInputStream.read(packetBytes); for(int i=0;i<bytesAvailable;i++) { byte b = packetBytes[i]; if(b == delimiter) { byte[] encodedBytes = new byte[readBufferPosition]; readBufferPosition = 0; { public void run() { t1=t1+data; myLabel.setText(data); } }); } else { readBuffer[readBufferPosition++] = b; } } } } { stopWorker = true; } } } }); workerThread.start(); } { msg += "\n"; mmOutputStream.write(msg.getBytes()); myLabel.setText("Data Sent"); } { stopWorker = true; mmOutputStream.close(); mmInputStream.close(); mmSocket.close(); myLabel.setText("Bluetooth Closed"); } }
Standard input is empty
Main.java:18: error: class MainActivity is public, should be declared in a file named MainActivity.java
public class MainActivity extends Activity
^
Main.java:1: error: package android.app does not exist
import android.app.Activity;
^
Main.java:2: error: package android.bluetooth does not exist
import android.bluetooth.BluetoothAdapter;
^
Main.java:3: error: package android.bluetooth does not exist
import android.bluetooth.BluetoothDevice;
^
Main.java:4: error: package android.bluetooth does not exist
import android.bluetooth.BluetoothSocket;
^
Main.java:5: error: package android.content does not exist
import android.content.Intent;
^
Main.java:6: error: package android.os does not exist
import android.os.Bundle;
^
Main.java:7: error: package android.os does not exist
import android.os.Handler;
^
Main.java:8: error: package android.view does not exist
import android.view.View;
^
Main.java:9: error: package android.widget does not exist
import android.widget.TextView;
^
Main.java:10: error: package android.widget does not exist
import android.widget.EditText;
^
Main.java:11: error: package android.widget does not exist
import android.widget.Button;
^
Main.java:18: error: cannot find symbol
public class MainActivity extends Activity
^
symbol: class Activity
Main.java:20: error: cannot find symbol
TextView myLabel;
^
symbol: class TextView
location: class MainActivity
Main.java:21: error: cannot find symbol
EditText myTextbox;
^
symbol: class EditText
location: class MainActivity
Main.java:22: error: cannot find symbol
BluetoothAdapter mBluetoothAdapter;
^
symbol: class BluetoothAdapter
location: class MainActivity
Main.java:23: error: cannot find symbol
BluetoothSocket mmSocket;
^
symbol: class BluetoothSocket
location: class MainActivity
Main.java:24: error: cannot find symbol
BluetoothDevice mmDevice;
^
symbol: class BluetoothDevice
location: class MainActivity
Main.java:34: error: cannot find symbol
public void onCreate(Bundle savedInstanceState)
^
symbol: class Bundle
location: class MainActivity
Main.java:33: error: method does not override or implement a method from a supertype
@Override
^
Main.java:36: error: cannot find symbol
super.onCreate(savedInstanceState);
^
symbol: variable super
location: class MainActivity
Main.java:37: error: package R does not exist
setContentView(R.layout.activity_main);
^
Main.java:39: error: cannot find symbol
Button openButton = (Button)findViewById(R.id.open);
^
symbol: class Button
location: class MainActivity
Main.java:39: error: cannot find symbol
Button openButton = (Button)findViewById(R.id.open);
^
symbol: class Button
location: class MainActivity
Main.java:39: error: package R does not exist
Button openButton = (Button)findViewById(R.id.open);
^
Main.java:40: error: cannot find symbol
Button sendButton = (Button)findViewById(R.id.send);
^
symbol: class Button
location: class MainActivity
Main.java:40: error: cannot find symbol
Button sendButton = (Button)findViewById(R.id.send);
^
symbol: class Button
location: class MainActivity
Main.java:40: error: package R does not exist
Button sendButton = (Button)findViewById(R.id.send);
^
Main.java:41: error: cannot find symbol
Button closeButton = (Button)findViewById(R.id.close);
^
symbol: class Button
location: class MainActivity
Main.java:41: error: cannot find symbol
Button closeButton = (Button)findViewById(R.id.close);
^
symbol: class Button
location: class MainActivity
Main.java:41: error: package R does not exist
Button closeButton = (Button)findViewById(R.id.close);
^
Main.java:42: error: cannot find symbol
myLabel = (TextView)findViewById(R.id.label);
^
symbol: class TextView
location: class MainActivity
Main.java:42: error: package R does not exist
myLabel = (TextView)findViewById(R.id.label);
^
Main.java:43: error: cannot find symbol
myTextbox = (EditText)findViewById(R.id.entry);
^
symbol: class EditText
location: class MainActivity
Main.java:43: error: package R does not exist
myTextbox = (EditText)findViewById(R.id.entry);
^
Main.java:46: error: package View does not exist
openButton.setOnClickListener(new View.OnClickListener()
^
Main.java:60: error: package View does not exist
sendButton.setOnClickListener(new View.OnClickListener()
^
Main.java:74: error: package View does not exist
closeButton.setOnClickListener(new View.OnClickListener()
^
Main.java:89: error: cannot find symbol
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
^
symbol: variable BluetoothAdapter
location: class MainActivity
Main.java:97: error: cannot find symbol
Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
^
symbol: class Intent
location: class MainActivity
Main.java:97: error: cannot find symbol
Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
^
symbol: class Intent
location: class MainActivity
Main.java:97: error: cannot find symbol
Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
^
symbol: variable BluetoothAdapter
location: class MainActivity
Main.java:101: error: cannot find symbol
Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
^
symbol: class BluetoothDevice
location: class MainActivity
Main.java:104: error: cannot find symbol
for(BluetoothDevice device : pairedDevices)
^
symbol: class BluetoothDevice
location: class MainActivity
Main.java:131: error: cannot find symbol
final Handler handler = new Handler();
^
symbol: class Handler
location: class MainActivity
Main.java:131: error: cannot find symbol
final Handler handler = new Handler();
^
symbol: class Handler
location: class MainActivity
46 errors
Standard output is empty