Thursday, April 14, 2016

How Check Bluetooth is Available or Not on your Device

Hi ... Dear All ..Today I am uploading a superb example to draw To Check Bluetooth is Available or Not on your Device.

Please check.
I am using Android Studio 1.5.1
Minimun SDK API 19
Target SDK API 23
Please Like us & put your valuable suggestions in comment box.
***** check on physical device
*****  Default layout file nothing added
**** we have to use BluetoothAdapter class for this and method is getDefaultAdapter()

A. Java Code - MainActivity.java

package com.exam.ravi.bluetoothex1;

import android.bluetooth.BluetoothAdapter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    BluetoothAdapter bluetoothAdapter;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
         if(bluetoothAdapter!=null)
         {
        Toast.makeText(this,"Bluetooth Is Available ",Toast.LENGTH_LONG).show();
        }
        else         {
         Toast.makeText(this,"Bluetooth Not Available " ,Toast.LENGTH_LONG).show();

         }
    }
}

No comments:

Post a Comment