package com.example.bluetoothserver; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.util.UUID; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothServerSocket; import android.bluetooth.BluetoothSocket; import android.content.Intent; import android.util.Log; import android.view.Menu; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import android.widget.LinearLayout.LayoutParams; public class MainActivity extends Activity { static TextView textview1; private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); private final int REQUEST_ENABLE_BT = 2; private BluetoothAdapter mBluetoothAdapter = null; private final static int MESSAGE_READ = 1; private static Handler mHandler = new Handler(){ if(message.what == MESSAGE_READ){ Log.e("handler",str); textview1.setText(textview1.getText()+str); } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textview1 = (TextView)findViewById(R.id.textView1); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); StartBluetooth(); AT = new AcceptThread(); AT.start(); } @Override // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } //開啟藍芽 public void StartBluetooth(){ // 如果裝置不支援藍芽 if (mBluetoothAdapter == null) { Toast.makeText(this, "Bluetooth is not available.", Toast.LENGTH_LONG).show(); finish(); return; } // 如果藍芽沒有開啟 if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } } //bluetooth server private final BluetoothServerSocket mmServerSocket; public AcceptThread() { // Use a temporary object that is later assigned to mmServerSocket, // because mmServerSocket is final BluetoothServerSocket tmp = null; try { // MY_UUID is the app's UUID string, also used by the client code tmp = mBluetoothAdapter.listenUsingRfcommWithServiceRecord("BluetoothServer", MY_UUID); Log.e("listenUsingRfcommWithServiceRecord","error"); } mmServerSocket = tmp; } public void run() { BluetoothSocket socket = null; // Keep listening until exception occurs or a socket is returned while (true) { try { socket = mmServerSocket.accept(); Log.e("listen","listen"); Log.e("listen","listen over"); break; } // If a connection was accepted if (socket != null) { // Do work to manage the connection (in a separate thread) CT.start(); Log.e("Connected","Connected"); //Log.e("socketclose","socketclose"); //mmServerSocket.close(); break; } } } /** Will cancel the listening socket, and cause the thread to finish */ public void cancel() { try { mmServerSocket.close(); } } private BluetoothSocket mmSocket; public ConnectedThread(BluetoothSocket socket) { mmSocket = socket; Log.e("a","a"); // Get the input and output streams, using temp objects because // member streams are final try { mmInStream = socket.getInputStream(); Log.e("get","get"); Log.e("error","error"); } } @Override public void run() { BufferedReader br; Log.e("br",br.toString()); // Keep listening to the InputStream until an exception occurs try { while ((line = br.readLine())!=null) { MainActivity.mHandler.obtainMessage(MESSAGE_READ, line).sendToTarget(); Log.e("line",line); } // TODO Auto-generated catch block Log.e("BufferedReader excrption",tmp); e.printStackTrace(); } Log.e("txt",tmp); cancel(); } /* Call this from the main activity to shutdown the connection */ public void cancel() { try { mmSocket.close(); } } }
Standard input is empty
Main.java:24: error: class MainActivity is public, should be declared in a file named MainActivity.java
public class MainActivity extends Activity {
^
Main.java:9: error: package android.os does not exist
import android.os.Bundle;
^
Main.java:10: error: package android.os does not exist
import android.os.Handler;
^
Main.java:11: error: package android.os does not exist
import android.os.Message;
^
Main.java:12: error: package android.app does not exist
import android.app.Activity;
^
Main.java:13: error: package android.bluetooth does not exist
import android.bluetooth.BluetoothAdapter;
^
Main.java:14: error: package android.bluetooth does not exist
import android.bluetooth.BluetoothServerSocket;
^
Main.java:15: error: package android.bluetooth does not exist
import android.bluetooth.BluetoothSocket;
^
Main.java:16: error: package android.content does not exist
import android.content.Intent;
^
Main.java:17: error: package android.util does not exist
import android.util.Log;
^
Main.java:18: error: package android.view does not exist
import android.view.Menu;
^
Main.java:19: error: package android.widget does not exist
import android.widget.LinearLayout;
^
Main.java:20: error: package android.widget does not exist
import android.widget.TextView;
^
Main.java:21: error: package android.widget does not exist
import android.widget.Toast;
^
Main.java:22: error: package android.widget.LinearLayout does not exist
import android.widget.LinearLayout.LayoutParams;
^
Main.java:24: error: cannot find symbol
public class MainActivity extends Activity {
^
symbol: class Activity
Main.java:25: error: cannot find symbol
static TextView textview1;
^
symbol: class TextView
location: class MainActivity
Main.java:28: error: cannot find symbol
private BluetoothAdapter mBluetoothAdapter = null;
^
symbol: class BluetoothAdapter
location: class MainActivity
Main.java:31: error: cannot find symbol
private static Handler mHandler = new Handler(){
^
symbol: class Handler
location: class MainActivity
Main.java:41: error: cannot find symbol
protected void onCreate(Bundle savedInstanceState) {
^
symbol: class Bundle
location: class MainActivity
Main.java:53: error: cannot find symbol
public boolean onCreateOptionsMenu(Menu menu) {
^
symbol: class Menu
location: class MainActivity
Main.java:80: error: cannot find symbol
private final BluetoothServerSocket mmServerSocket;
^
symbol: class BluetoothServerSocket
location: class MainActivity.AcceptThread
Main.java:128: error: cannot find symbol
private BluetoothSocket mmSocket;
^
symbol: class BluetoothSocket
location: class MainActivity.ConnectedThread
Main.java:131: error: cannot find symbol
public ConnectedThread(BluetoothSocket socket) {
^
symbol: class BluetoothSocket
location: class MainActivity.ConnectedThread
Main.java:31: error: cannot find symbol
private static Handler mHandler = new Handler(){
^
symbol: class Handler
location: class MainActivity
Main.java:42: error: cannot find symbol
super.onCreate(savedInstanceState);
^
symbol: variable super
location: class MainActivity
Main.java:43: error: package R does not exist
setContentView(R.layout.activity_main);
^
Main.java:44: error: cannot find symbol
textview1 = (TextView)findViewById(R.id.textView1);
^
symbol: class TextView
location: class MainActivity
Main.java:44: error: package R does not exist
textview1 = (TextView)findViewById(R.id.textView1);
^
Main.java:45: error: cannot find symbol
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
^
symbol: variable BluetoothAdapter
location: class MainActivity
Main.java:40: error: method does not override or implement a method from a supertype
@Override
^
Main.java:55: error: package R does not exist
getMenuInflater().inflate(R.menu.main, menu);
^
Main.java:55: error: cannot find symbol
getMenuInflater().inflate(R.menu.main, menu);
^
symbol: method getMenuInflater()
location: class MainActivity
Main.java:52: error: method does not override or implement a method from a supertype
@Override
^
Main.java:67: error: cannot find symbol
Toast.LENGTH_LONG).show();
^
symbol: variable Toast
location: class MainActivity
Main.java:65: error: cannot find symbol
Toast.makeText(this,
^
symbol: variable Toast
location: class MainActivity
Main.java:68: error: cannot find symbol
finish();
^
symbol: method finish()
location: class MainActivity
Main.java:73: error: cannot find symbol
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
^
symbol: class Intent
location: class MainActivity
Main.java:73: error: cannot find symbol
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
^
symbol: class Intent
location: class MainActivity
Main.java:73: error: cannot find symbol
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
^
symbol: variable BluetoothAdapter
location: class MainActivity
Main.java:85: error: cannot find symbol
BluetoothServerSocket tmp = null;
^
symbol: class BluetoothServerSocket
location: class MainActivity.AcceptThread
Main.java:90: error: cannot find symbol
Log.e("listenUsingRfcommWithServiceRecord","error");
^
symbol: variable Log
location: class MainActivity.AcceptThread
Main.java:96: error: cannot find symbol
BluetoothSocket socket = null;
^
symbol: class BluetoothSocket
location: class MainActivity.AcceptThread
Main.java:101: error: cannot find symbol
Log.e("listen","listen");
^
symbol: variable Log
location: class MainActivity.AcceptThread
Main.java:103: error: cannot find symbol
Log.e("listen","listen over");
^
symbol: variable Log
location: class MainActivity.AcceptThread
Main.java:111: error: cannot find symbol
Log.e("Connected","Connected");
^
symbol: variable Log
location: class MainActivity.AcceptThread
Main.java:133: error: cannot find symbol
Log.e("a","a");
^
symbol: variable Log
location: class MainActivity.ConnectedThread
Main.java:138: error: cannot find symbol
Log.e("get","get");
^
symbol: variable Log
location: class MainActivity.ConnectedThread
Main.java:140: error: cannot find symbol
Log.e("error","error");
^
symbol: variable Log
location: class MainActivity.ConnectedThread
Main.java:149: error: cannot find symbol
Log.e("br",br.toString());
^
symbol: variable Log
location: class MainActivity.ConnectedThread
Main.java:154: error: cannot find symbol
Log.e("line",line);
^
symbol: variable Log
location: class MainActivity.ConnectedThread
Main.java:160: error: cannot find symbol
Log.e("BufferedReader excrption",tmp);
^
symbol: variable Log
location: class MainActivity.ConnectedThread
Main.java:164: error: cannot find symbol
Log.e("txt",tmp);
^
symbol: variable Log
location: class MainActivity.ConnectedThread
53 errors
Standard output is empty