Code example for BluetoothAdapter

Methods: getScanModeisEnabled

0
    public void onStart() { 
        super.onStart(); 
        if(D) Log.e(TAG, "++ ON START ++");
 
        // If BT is not on, request that it be enabled. 
        if (!mAdapter.isEnabled()) {
            Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
        }else { 
        	ensureDiscoverable(); 
        	SetupCluster(); 
        } 
        
    } 
     
    @Override 
    public synchronized void onResume() { 
        super.onResume(); 
        if(D) Log.e(TAG, "+ ON RESUME +");
        if (mState!=STATE_DISC){
        	ensureDiscoverable(); 
        } 
    } 
 
    @Override 
    public synchronized void onPause() { 
        super.onPause(); 
        if(D) Log.e(TAG, "- ON PAUSE -");
        mHandler.removeCallbacks(mUpdateTimeTask);
         
        BTPrefs = getSharedPreferences(data_strings,0);
        String Adname = BTPrefs.getString("OrigAdapName","MyBT");
    	boolean b=mAdapter.setName(Adname);
    	if(b){
    		Intent discoverableintent = new
    		Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    		discoverableintent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 1);
    		startActivity(discoverableintent);
    		mState=STATE_NoDISC;
    	} 
    	 
    } 
 
    @Override 
    public void onStop() { 
        super.onStop(); 
        if(D) Log.e(TAG, "-- ON STOP --");
        mHandler.removeCallbacks(mUpdateTimeTask);
         
        BTPrefs = getSharedPreferences(data_strings,0);
        String Adname = BTPrefs.getString("OrigAdapName",null);
    	boolean b=mAdapter.setName(Adname);
    	if(b){
    		Intent discoverableintent = new
    		Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
    		discoverableintent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 1);
    		startActivity(discoverableintent);
    		mState=STATE_NoDISC;
    	} 
         
    } 
 
    @Override 
    public void onDestroy() { 
        super.onDestroy(); 
        if(D) Log.e(TAG, "--- ON DESTROY ---");
    } 
     
    private void SetupCluster() { 
    	 
    	Intent c_id_Intent = new Intent(this, Setup_list.class);
        startActivityForResult(c_id_Intent, REQUEST_SETUP);
    } 
     
  private void formCluster() { 
	  BTPrefs = getSharedPreferences(data_strings,0);
      String Adname = BTPrefs.getString("C_ID",null);
      cluster_id_length = (int) BTPrefs.getLong("C_ID_length",3);
      freq = BTPrefs.getLong("freq",DEF_FREQ);
  	  boolean b=mAdapter.setName(Adname);
  	  if(b&&Adname!=null){
      Intent c_id_Intent = new Intent(this, DeviceList.class);
      startActivityForResult(c_id_Intent, REQUEST_TIMESTAMP);
      }else{ 
    	  SetupCluster(); 
      } 
    } 
   
  private void Synchrony(Intent data) {
  	    String Adname = BTPrefs.getString("C_ID",null) + "System.currentTimeMillis()";
  	    boolean b=mAdapter.setName(Adname);
  	    devices_disc = data.getStringArrayListExtra (EXTRA_DEVICE_ADDRESS);
  	    if(b&&devices_disc.size()!=0){
  	    int i=devices_disc.size();
  	    long sum=0;
  	    for(int j=0;j<i;j++){
  	    	String adapName = devices_disc.get(j);
  	    	String time = adapName.substring(cluster_id_length,adapName.length());
  	    	sum = sum + Long.valueOf(time).longValue(); 
  	    	 
  	    } 
  	    time_stamp = sum;
  	    /* 
  	     * Intent SyncIntent = new Intent(for sending to flashing algo); 
                 
           SyncIntent.putLong(avg_time, time_stamp); 
           startActivity(intent);*/ 
  	     
  	    if(flag ==0){
  	    	mHandler.removeCallbacks(mUpdateTimeTask);
            mHandler.postDelayed(mUpdateTimeTask, (int)5000/freq);
            flag = 1;
  	    } 
  	      
  	   
  	    } else{ 
  	    	formCluster(); 
  	    } 
  } 
   
  private Runnable mUpdateTimeTask = new Runnable() {
      public void run() { 
      	try { 
      		formCluster(); 
      		flag=0; 
			} catch (Exception e) { 
			} 
      	 
          mHandler.postDelayed(this, 10000); 
      } 
  }; 
     
    private void ensureDiscoverable() { 
        if(D) Log.d(TAG, "ensure discoverable");
        if (mAdapter.getScanMode() !=
            BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
            Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
            discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0);
            startActivity(discoverableIntent);
            mState=STATE_DISC;
Connect your IDE to all the code out there  Get Codota for Java