Click here to Skip to main content
15,885,145 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Java
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);
    }
}
Posted
Updated 2-Jan-15 10:13am
v2
Comments
ZurdoDev 2-Jan-15 17:25pm    
And the error is...?

1 solution

The error would help. but by just a quick look, the mArrayAdapter could be null.
try something like this in onCreate:
Java
mArrayAdapter = new Set<bluetoothdevice>;</bluetoothdevice>

before;
bluetoothadapter();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900