title: Bluetooth app not working on devices running on Lollipop
body: <p>I made a Bluetooth app. It works fine in <code>Nougat</code>, <code>Marshmallow</code>, <code>Jelly Bean</code>, <code>KitKat</code> but for reason, it crashes in Android <code>Lollipop</code> when <code>Discover</code> button (which discovers all the discoverable devices) is clicked. </p>
  
  <p>Here is the method which gets triggered on clicking <code>Discover</code> button -</p>
  
  <pre><code>private void discoverDevices() {
          Log.d(TAG, "btnDiscover: Looking for unpaired devices.");
  
          if(mBluetoothAdapter.isDiscovering()){
              mBluetoothAdapter.cancelDiscovery();
              Log.d(TAG, "btnDiscover: Canceling discovery.");
  
              //check BT permissions in manifest
              checkBTPermissions();
  
              mBluetoothAdapter.startDiscovery();
              IntentFilter discoverDevicesIntent = new IntentFilter(BluetoothDevice.ACTION_FOUND);
              registerReceiver(mBroadcastReceiver3, discoverDevicesIntent);
          }
          if(!mBluetoothAdapter.isDiscovering()){
  
              //check BT permissions in manifest
              checkBTPermissions();
  
              mBluetoothAdapter.startDiscovery();
              IntentFilter discoverDevicesIntent = new IntentFilter(BluetoothDevice.ACTION_FOUND);
              registerReceiver(mBroadcastReceiver3, discoverDevicesIntent);
          }
  
  
      }
  </code></pre>
  
  <p><strong>CheckBTPermissions()-</strong></p>
  
  <pre><code>private void checkBTPermissions() {
  
          if(Build.VERSION.SDK_INT &gt; Build.VERSION_CODES.LOLLIPOP){
              int permissionCheck = this.checkSelfPermission("Manifest.permission.ACCESS_FINE_LOCATION");
              permissionCheck += this.checkSelfPermission("Manifest.permission.ACCESS_COARSE_LOCATION");
              if (permissionCheck != 0) {
  
                  this.requestPermissions(new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, 1001); //Any number
              }
          }else{
              Log.d(TAG, "checkBTPermissions: No need to check permissions. SDK version 
  =&lt; LOLLIPOP.");
          }
      }
  </code></pre>
  
  <p><strong>Permissions in Manifest file-</strong></p>
  
  <pre><code>&lt;uses-feature android:name="android.hardware.bluetooth" /&gt;
  &lt;uses-permission android:name="android.permission.BLUETOOTH" /&gt;
  &lt;uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/&gt;
  &lt;uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" /&gt;
  </code></pre>
  
  <p><strong>build.gradle-</strong></p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 25
      buildToolsVersion "25.0.0"
      defaultConfig {
          applicationId "com.example.hpi5.bluetooth"
          minSdkVersion 16
          targetSdkVersion 25
          versionCode 1
          versionName "1.0"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      }
      buildTypes {
          release {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
  }
  
  dependencies {
      compile fileTree(dir: 'libs', include: ['*.jar'])
      androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
          exclude group: 'com.android.support', module: 'support-annotations'
      })
      compile 'com.android.support:appcompat-v7:25.3.1'
      compile 'com.android.support.constraint:constraint-layout:1.0.2'
      testCompile 'junit:junit:4.12'
  }
  </code></pre>
  
  <p><strong>I have not tested this app on Lollipop myself as I don't have any device running on Android L.</strong> I got to know about the crash from a friend of mine.</p>
  
  <p><strong>EDIT: I managed to arrange the logs.</strong> </p>
  
  <pre><code>07-07 19:29:00.219 30852-30852/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                     Process: com.example.hpi5.bluetooth, PID: 30852
                                                     java.lang.NoSuchMethodError: No virtual method checkSelfPermission(Ljava/lang/String;)I in class Lcom/example/hpi5/bluetooth/MainActivity; or its super classes (declaration of 'com.example.hpi5.bluetooth.MainActivity' appears in /data/app/com.example.hpi5.bluetooth-1/base.apk)
                                                         at com.example.hpi5.bluetooth.MainActivity.checkBTPermissions(MainActivity.java:243)
                                                         at com.example.hpi5.bluetooth.MainActivity.discoverDevices(MainActivity.java:230)
                                                         at com.example.hpi5.bluetooth.MainActivity.access$100(MainActivity.java:24)
                                                         at com.example.hpi5.bluetooth.MainActivity$7.onClick(MainActivity.java:189)
                                                         at android.view.View.performClick(View.java:4923)
                                                         at android.view.View$PerformClick.run(View.java:20341)
                                                         at android.os.Handler.handleCallback(Handler.java:815)
                                                         at android.os.Handler.dispatchMessage(Handler.java:104)
                                                         at android.os.Looper.loop(Looper.java:194)
                                                         at android.app.ActivityThread.main(ActivityThread.java:5717)
                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                         at java.lang.reflect.Method.invoke(Method.java:372)
                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
  </code></pre>