2017-11-23 7 views
1

私は次のように、Androidの中に青歯が検出可能にするためにコードを学んだ:だからBluetoothを発見できないようにする方法は?

Intent discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); 
discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300); 
startActivity(discoverableIntent);` = 

、どのように私は、人為的に、すぐに私はそれを見つけ作るとして青歯の未発見することができますか?

ありがとうございました!

+2

解決策は、発見可能な時間制限を1秒に設定することです(これまでに認識しているのは唯一の解決策です)。この回答を見てください:https://stackoverflow.com/questions/2938421/disable-bluetooth-discoverable-mode-on-android – lidkxx

+0

これは良い解決策です、ありがとう! –

答えて

1

私はまだそれを理解していませんが、私の方法で見つけました、それは私のプロジェクトで動作します!

public void closeDiscoverableTimeout() { 
    BluetoothAdapter adapter=BluetoothAdapter.getDefaultAdapter(); 
    try { 
     Method setDiscoverableTimeout = BluetoothAdapter.class.getMethod("setDiscoverableTimeout", int.class); 
     setDiscoverableTimeout.setAccessible(true); 
     Method setScanMode =BluetoothAdapter.class.getMethod("setScanMode", int.class,int.class); 
     setScanMode.setAccessible(true); 

     setDiscoverableTimeout.invoke(adapter, 1); 
     setScanMode.invoke(adapter, BluetoothAdapter.SCAN_MODE_CONNECTABLE,1); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 
関連する問題