package com.example.i.t; import java.util.Set; import android.support.v7.app.ActionBarActivity; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.MenuItem; import android.view.View; import android.widget.Button; public class MainActivity extends ActionBarActivity { private static final int REQUEST_ENABLE_BT = 0; private static final Set<bluetoothdevice> mArrayAdapter = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); runfyita(); runfyitb(); bluetoothadapter(); } private void bluetoothadapter() { // TODO Auto-generated method stub BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent (BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); Set<bluetoothdevice> pairedDevices = mBluetoothAdapter.getBondedDevices(); if (pairedDevices.size() > 0) { for (BluetoothDevice device : pairedDevices) { mArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } } final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { // TODO Auto-generated method stub String action = intent.getAction(); if (BluetoothDevice.ACTION_FOUND.equals(action)) { BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); mArrayAdapter.add(device.getName() + "\n" + device.getAddress()); } } }; } } private void runfyitb() { // TODO Auto-generated method stub Button button = (Button) findViewById(R.id.fyitb); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent (MainActivity.this, Fyitbtimetable.class); startActivity(intent); } }); } private void runfyita() { // TODO Auto-generated method stub Button button = (Button) findViewById(R.id.fyita); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(MainActivity.this, Fyitatimetable.class); startActivity(intent); } }); } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
mArrayAdapter = new Set<bluetoothdevice>;</bluetoothdevice>
bluetoothadapter();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)