package mashiro.fan; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Method; import java.util.UUID; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.content.Intent; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; public class MainActivity extends Activity { Button connect, button, button2, button3, button4, button5, button6, button7, button8, button9; TextView textView; TextView textView2; TextView textView3; Handler h; final int RECIEVE_MESSAGE = 1; // Status for Handler private BluetoothAdapter btAdapter = null; private BluetoothSocket btSocket = null; private StringBuilder sb = new StringBuilder(); private ConnectedThread mConnectedThread; // SPP UUID service private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); // MAC-address of Bluetooth module (you must edit this line) /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); h = new Handler() { public void handleMessage(android.os.Message msg) { switch (msg.what) { case RECIEVE_MESSAGE: // if receive massage byte[] readBuf = (byte[]) msg.obj; sb.append(strIncom); // append string int endOfLineIndex = sb.indexOf("\r\n"); // determine the end-of-line if (endOfLineIndex > 0) { // if end-of-line, sb.delete(0, sb.length()); // and clear textView.setText("現在時間: " + sbprint); // update TextView button.setEnabled(true); button2.setEnabled(true); button3.setEnabled(true); button4.setEnabled(true); button5.setEnabled(true); button6.setEnabled(true); button7.setEnabled(true); button8.setEnabled(true); } //Log.d(TAG, "...String:"+ sb.toString() + "Byte:" + msg.arg1 + "..."); break; } }; }; btAdapter = BluetoothAdapter.getDefaultAdapter(); // get Bluetooth adapter checkBTState(); button2.setOnClickListener(new OnClickListener() { mConnectedThread.write("g"); TextView text = (TextView) findViewById(R.id.textView3); text.setText("現在模式:自動模式"); button.setEnabled(true); button2.setEnabled(false); button3.setEnabled(false); button4.setEnabled(false); button5.setEnabled(false); button6.setEnabled(false); button7.setEnabled(false); button8.setEnabled(false); } }); button3.setOnClickListener(new OnClickListener() { mConnectedThread.write("c"); TextView text = (TextView) findViewById(R.id.textView2); text.setText("現在風速:強"); button.setEnabled(false); button2.setEnabled(true); button3.setEnabled(false); button4.setEnabled(true); button5.setEnabled(true); button6.setEnabled(true); button7.setEnabled(true); button8.setEnabled(true); } }); button4.setOnClickListener(new OnClickListener() { mConnectedThread.write("b"); TextView text = (TextView) findViewById(R.id.textView2); text.setText("現在風速:中"); button.setEnabled(false); button2.setEnabled(true); button3.setEnabled(true); button4.setEnabled(false); button5.setEnabled(true); button6.setEnabled(true); button7.setEnabled(true); button8.setEnabled(true); } }); button5.setOnClickListener(new OnClickListener() { mConnectedThread.write("a"); TextView text = (TextView) findViewById(R.id.textView2); text.setText("現在風速:弱"); button.setEnabled(false); button2.setEnabled(true); button3.setEnabled(true); button4.setEnabled(true); button5.setEnabled(false); button6.setEnabled(true); button7.setEnabled(true); button8.setEnabled(true); } }); button6.setOnClickListener(new OnClickListener() { mConnectedThread.write("d"); button.setEnabled(false); button2.setEnabled(true); button3.setEnabled(true); button4.setEnabled(true); button5.setEnabled(true); button6.setEnabled(false); button7.setEnabled(true); button8.setEnabled(true); } }); button7.setOnClickListener(new OnClickListener() { mConnectedThread.write("e"); button.setEnabled(false); button2.setEnabled(true); button3.setEnabled(true); button4.setEnabled(true); button5.setEnabled(true); button6.setEnabled(true); button7.setEnabled(false); button8.setEnabled(true); } }); button8.setOnClickListener(new OnClickListener() { mConnectedThread.write("f"); button.setEnabled(false); button2.setEnabled(true); button3.setEnabled(true); button4.setEnabled(true); button5.setEnabled(true); button6.setEnabled(true); button7.setEnabled(true); button8.setEnabled(false); } }); @Override TextView text = (TextView) findViewById(R.id.textView3); text.setText("現在模式:手動模式"); button.setEnabled(false); button2.setEnabled(true); button3.setEnabled(true); button4.setEnabled(true); button5.setEnabled(true); button6.setEnabled(true); button7.setEnabled(true); button8.setEnabled(true); } }); } if(Build.VERSION.SDK_INT >= 10){ try { final Method m = device.getClass().getMethod("createInsecureRfcommSocketToServiceRecord", new Class[] { UUID.class }); return (BluetoothSocket) m.invoke(device, MY_UUID); Log.e(TAG, "Could not create Insecure RFComm Connection",e); } } return device.createRfcommSocketToServiceRecord(MY_UUID); } @Override public void onResume() { super.onResume(); Log.d(TAG, "...onResume - try connect..."); // Set up a pointer to the remote node using it's address. BluetoothDevice device = btAdapter.getRemoteDevice(address); // Two things are needed to make a connection: // A MAC address, which we got above. // A Service ID or UUID. In this case we are using the // UUID for SPP. try { btSocket = createBluetoothSocket(device); errorExit("Fatal Error", "In onResume() and socket create failed: " + e.getMessage() + "."); } // Discovery is resource intensive. Make sure it isn't going on // when you attempt to connect and pass your message. btAdapter.cancelDiscovery(); // Establish the connection. This will block until it connects. Log.d(TAG, "...Connecting..."); try { btSocket.connect(); Log.d(TAG, "....Connection ok..."); try { btSocket.close(); errorExit("Fatal Error", "In onResume() and unable to close socket during connection failure" + e2.getMessage() + "."); } } // Create a data stream so we can talk to server. Log.d(TAG, "...Create Socket..."); mConnectedThread = new ConnectedThread(btSocket); mConnectedThread.start(); } @Override public void onPause() { super.onPause(); Log.d(TAG, "...In onPause()..."); try { btSocket.close(); errorExit("Fatal Error", "In onPause() and failed to close socket." + e2.getMessage() + "."); } } private void checkBTState() { // Check for Bluetooth support and then check to make sure it is turned on // Emulator doesn't support Bluetooth and will return null if(btAdapter==null) { errorExit("Fatal Error", "Bluetooth not support"); } else { if (btAdapter.isEnabled()) { Log.d(TAG, "...Bluetooth ON..."); } else { //Prompt user to turn on Bluetooth Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, 1); } } } Toast.makeText(getBaseContext(), title + " - " + message, Toast.LENGTH_LONG).show(); finish(); } public ConnectedThread(BluetoothSocket socket) { // Get the input and output streams, using temp objects because // member streams are final try { tmpIn = socket.getInputStream(); tmpOut = socket.getOutputStream(); mmInStream = tmpIn; mmOutStream = tmpOut; } public void run() { byte[] buffer = new byte[256]; // buffer store for the stream int bytes; // bytes returned from read() // Keep listening to the InputStream until an exception occurs while (true) { try { // Read from the InputStream bytes = mmInStream.read(buffer); // Get number of bytes and message in "buffer" h.obtainMessage(RECIEVE_MESSAGE, bytes, -1, buffer).sendToTarget(); // Send to message queue Handler break; } } } /* Call this from the main activity to send data to the remote device */ Log.d(TAG, "...Data to send: " + message + "..."); byte[] msgBuffer = message.getBytes(); try { mmOutStream.write(msgBuffer); Log.d(TAG, "...Error data send: " + e.getMessage() + "..."); } } } }
Standard input is empty
Main.java:26: error: class MainActivity is public, should be declared in a file named MainActivity.java
public class MainActivity extends Activity {
^
Main.java:11: error: package android.app does not exist
import android.app.Activity;
^
Main.java:12: error: package android.bluetooth does not exist
import android.bluetooth.BluetoothAdapter;
^
Main.java:13: error: package android.bluetooth does not exist
import android.bluetooth.BluetoothDevice;
^
Main.java:14: error: package android.bluetooth does not exist
import android.bluetooth.BluetoothSocket;
^
Main.java:15: error: package android.content does not exist
import android.content.Intent;
^
Main.java:16: error: package android.os does not exist
import android.os.Build;
^
Main.java:17: error: package android.os does not exist
import android.os.Bundle;
^
Main.java:18: error: package android.os does not exist
import android.os.Handler;
^
Main.java:19: error: package android.util does not exist
import android.util.Log;
^
Main.java:20: error: package android.view does not exist
import android.view.View;
^
Main.java:21: error: package android.view.View does not exist
import android.view.View.OnClickListener;
^
Main.java:22: error: package android.widget does not exist
import android.widget.Button;
^
Main.java:23: error: package android.widget does not exist
import android.widget.TextView;
^
Main.java:24: error: package android.widget does not exist
import android.widget.Toast;
^
Main.java:26: error: cannot find symbol
public class MainActivity extends Activity {
^
symbol: class Activity
Main.java:29: error: cannot find symbol
Button connect, button, button2, button3, button4, button5, button6, button7, button8, button9;
^
symbol: class Button
location: class MainActivity
Main.java:31: error: cannot find symbol
TextView textView;
^
symbol: class TextView
location: class MainActivity
Main.java:33: error: cannot find symbol
TextView textView2;
^
symbol: class TextView
location: class MainActivity
Main.java:34: error: cannot find symbol
TextView textView3;
^
symbol: class TextView
location: class MainActivity
Main.java:37: error: cannot find symbol
Handler h;
^
symbol: class Handler
location: class MainActivity
Main.java:40: error: cannot find symbol
private BluetoothAdapter btAdapter = null;
^
symbol: class BluetoothAdapter
location: class MainActivity
Main.java:41: error: cannot find symbol
private BluetoothSocket btSocket = null;
^
symbol: class BluetoothSocket
location: class MainActivity
Main.java:54: error: cannot find symbol
public void onCreate(Bundle savedInstanceState) {
^
symbol: class Bundle
location: class MainActivity
Main.java:221: error: cannot find symbol
private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException {
^
symbol: class BluetoothDevice
location: class MainActivity
Main.java:221: error: cannot find symbol
private BluetoothSocket createBluetoothSocket(BluetoothDevice device) throws IOException {
^
symbol: class BluetoothSocket
location: class MainActivity
Main.java:315: error: cannot find symbol
public ConnectedThread(BluetoothSocket socket) {
^
symbol: class BluetoothSocket
location: class MainActivity.ConnectedThread
Main.java:53: error: method does not override or implement a method from a supertype
@Override
^
Main.java:55: error: cannot find symbol
super.onCreate(savedInstanceState);
^
symbol: variable super
location: class MainActivity
Main.java:57: error: package R does not exist
setContentView(R.layout.activity_main);
^
Main.java:59: error: cannot find symbol
connect = (Button) findViewById(R.id.connect);
^
symbol: class Button
location: class MainActivity
Main.java:59: error: package R does not exist
connect = (Button) findViewById(R.id.connect);
^
Main.java:60: error: cannot find symbol
button = (Button) findViewById(R.id.button);
^
symbol: class Button
location: class MainActivity
Main.java:60: error: package R does not exist
button = (Button) findViewById(R.id.button);
^
Main.java:61: error: cannot find symbol
button2 = (Button) findViewById(R.id.button2);
^
symbol: class Button
location: class MainActivity
Main.java:61: error: package R does not exist
button2 = (Button) findViewById(R.id.button2);
^
Main.java:62: error: cannot find symbol
button3 = (Button) findViewById(R.id.button3);
^
symbol: class Button
location: class MainActivity
Main.java:62: error: package R does not exist
button3 = (Button) findViewById(R.id.button3);
^
Main.java:63: error: cannot find symbol
button4 = (Button) findViewById(R.id.button4);
^
symbol: class Button
location: class MainActivity
Main.java:63: error: package R does not exist
button4 = (Button) findViewById(R.id.button4);
^
Main.java:64: error: cannot find symbol
button5 = (Button) findViewById(R.id.button5);
^
symbol: class Button
location: class MainActivity
Main.java:64: error: package R does not exist
button5 = (Button) findViewById(R.id.button5);
^
Main.java:65: error: cannot find symbol
button6 = (Button) findViewById(R.id.button6);
^
symbol: class Button
location: class MainActivity
Main.java:65: error: package R does not exist
button6 = (Button) findViewById(R.id.button6);
^
Main.java:66: error: cannot find symbol
button7 = (Button) findViewById(R.id.button7);
^
symbol: class Button
location: class MainActivity
Main.java:66: error: package R does not exist
button7 = (Button) findViewById(R.id.button7);
^
Main.java:67: error: cannot find symbol
button8 = (Button) findViewById(R.id.button8);
^
symbol: class Button
location: class MainActivity
Main.java:67: error: package R does not exist
button8 = (Button) findViewById(R.id.button8);
^
Main.java:68: error: cannot find symbol
button9 = (Button) findViewById(R.id.button9); // for display the received data from the Arduino
^
symbol: class Button
location: class MainActivity
Main.java:68: error: package R does not exist
button9 = (Button) findViewById(R.id.button9); // for display the received data from the Arduino
^
Main.java:70: error: cannot find symbol
h = new Handler() {
^
symbol: class Handler
location: class MainActivity
Main.java:97: error: cannot find symbol
btAdapter = BluetoothAdapter.getDefaultAdapter(); // get Bluetooth adapter
^
symbol: variable BluetoothAdapter
location: class MainActivity
Main.java:100: error: cannot find symbol
button2.setOnClickListener(new OnClickListener() {
^
symbol: class OnClickListener
location: class MainActivity
Main.java:115: error: cannot find symbol
button3.setOnClickListener(new OnClickListener() {
^
symbol: class OnClickListener
location: class MainActivity
Main.java:131: error: cannot find symbol
button4.setOnClickListener(new OnClickListener() {
^
symbol: class OnClickListener
location: class MainActivity
Main.java:147: error: cannot find symbol
button5.setOnClickListener(new OnClickListener() {
^
symbol: class OnClickListener
location: class MainActivity
Main.java:163: error: cannot find symbol
button6.setOnClickListener(new OnClickListener() {
^
symbol: class OnClickListener
location: class MainActivity
Main.java:176: error: cannot find symbol
button7.setOnClickListener(new OnClickListener() {
^
symbol: class OnClickListener
location: class MainActivity
Main.java:189: error: cannot find symbol
button8.setOnClickListener(new OnClickListener() {
^
symbol: class OnClickListener
location: class MainActivity
Main.java:202: error: package View does not exist
button.setOnClickListener(new View.OnClickListener() {
^
Main.java:222: error: package Build does not exist
if(Build.VERSION.SDK_INT >= 10){
^
Main.java:225: error: cannot find symbol
return (BluetoothSocket) m.invoke(device, MY_UUID);
^
symbol: class BluetoothSocket
location: class MainActivity
Main.java:227: error: cannot find symbol
Log.e(TAG, "Could not create Insecure RFComm Connection",e);
^
symbol: variable Log
location: class MainActivity
Main.java:233: error: method does not override or implement a method from a supertype
@Override
^
Main.java:235: error: cannot find symbol
super.onResume();
^
symbol: variable super
location: class MainActivity
Main.java:237: error: cannot find symbol
Log.d(TAG, "...onResume - try connect...");
^
symbol: variable Log
location: class MainActivity
Main.java:240: error: cannot find symbol
BluetoothDevice device = btAdapter.getRemoteDevice(address);
^
symbol: class BluetoothDevice
location: class MainActivity
Main.java:258: error: cannot find symbol
Log.d(TAG, "...Connecting...");
^
symbol: variable Log
location: class MainActivity
Main.java:261: error: cannot find symbol
Log.d(TAG, "....Connection ok...");
^
symbol: variable Log
location: class MainActivity
Main.java:271: error: cannot find symbol
Log.d(TAG, "...Create Socket...");
^
symbol: variable Log
location: class MainActivity
Main.java:277: error: method does not override or implement a method from a supertype
@Override
^
Main.java:279: error: cannot find symbol
super.onPause();
^
symbol: variable super
location: class MainActivity
Main.java:281: error: cannot find symbol
Log.d(TAG, "...In onPause()...");
^
symbol: variable Log
location: class MainActivity
Main.java:297: error: cannot find symbol
Log.d(TAG, "...Bluetooth ON...");
^
symbol: variable Log
location: class MainActivity
Main.java:300: error: cannot find symbol
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
^
symbol: class Intent
location: class MainActivity
Main.java:300: error: cannot find symbol
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
^
symbol: class Intent
location: class MainActivity
Main.java:300: error: cannot find symbol
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
^
symbol: variable BluetoothAdapter
location: class MainActivity
Main.java:307: error: cannot find symbol
Toast.makeText(getBaseContext(), title + " - " + message, Toast.LENGTH_LONG).show();
^
symbol: method getBaseContext()
location: class MainActivity
Main.java:307: error: cannot find symbol
Toast.makeText(getBaseContext(), title + " - " + message, Toast.LENGTH_LONG).show();
^
symbol: variable Toast
location: class MainActivity
Main.java:307: error: cannot find symbol
Toast.makeText(getBaseContext(), title + " - " + message, Toast.LENGTH_LONG).show();
^
symbol: variable Toast
location: class MainActivity
Main.java:308: error: cannot find symbol
finish();
^
symbol: method finish()
location: class MainActivity
Main.java:348: error: cannot find symbol
Log.d(TAG, "...Data to send: " + message + "...");
^
symbol: variable Log
location: class MainActivity.ConnectedThread
Main.java:353: error: cannot find symbol
Log.d(TAG, "...Error data send: " + e.getMessage() + "...");
^
symbol: variable Log
location: class MainActivity.ConnectedThread
83 errors
Standard output is empty