6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Android 6 で Beacon を使うには

Last updated at Posted at 2016-06-02

Android 5 では動く AltBeacon が Android 6.0 ではエラーを吐いて動かなかった。

 D/BluetoothLeScanner: could not find callback wrapper

AndroidManifest.xml の記述だけではだめらしい。
# AndoidManifest.xml
 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

【Is Your Beacon App Ready for Android 6.0?】

ここにあるようにコードを加えて、ロケーションアクセスをダイアログで許可するようにして、やっと動くようになりました(>.<)ノ

public class MainActivity extends AppCompatActivity implements BeaconConsumer {

   private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      // Android M Permission check

      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
         if (this.checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            requestPermissions(new String[]{android.Manifest.permission.ACCESS_COARSE_LOCATION},PERMISSION_REQUEST_COARSE_LOCATION);
         }
      }
6
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?