Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.Manifest;

import android.bluetooth.BluetoothAdapter;
import android.content.Context;

import android.content.pm.PackageManager;

public class Main {
    public static boolean isBluetoothEnabled(Context context) {
        if (checkPermission(context, Manifest.permission.BLUETOOTH)) {
            BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
            if (mBluetoothAdapter != null) {
                return mBluetoothAdapter.isEnabled();
            }
        }
        return false;
    }

    public static boolean checkPermission(Context context, String permission) {
        int res = context.checkCallingOrSelfPermission(permission);
        return (res == PackageManager.PERMISSION_GRANTED);
    }
}