2014-12-29 4 views
0

아래는 사용 설정/사용 중지에 대한 코드이지만 기기 설정을 사용 중지하지는 않습니다.블루투스 또는 Android 기기의 카메라 또는 Wi-Fi를 사용 중지하고 맞춤 앱을 통해서만 사용 설정을 허용 할 수 있나요?

나는 안드로이드 장치의 블루투스 (카메라/와이파이) 기능을 비활성화하고 내 개인화 된 응용 프로그램을 통해서만이 기능을 활성화하는 방법을 알고 싶습니다. 사용자는 앱을 통해서만 블루투스를 사용할 수 있어야합니다.

BluetoothAdapter bluetoothAdapter = BluetoothAdapter 
      .getDefaultAdapter(); 
    boolean isEnabled = bluetoothAdapter.isEnabled(); 
    if (isEnabled) { 
     Toast.makeText(getApplicationContext(), "Enabled", 
       Toast.LENGTH_SHORT).show(); 
     bluetoothAdapter.disable(); 
    } else { 
     Toast.makeText(getApplicationContext(), "Not Enabled", 
       Toast.LENGTH_SHORT).show(); 
     bluetoothAdapter.enable(); 
    } 

답변

0

당신은 BluetoothAdapter.ACTION_STATE_CHANGED (link) 수신 브로드 캐스트 리시버를 구현해야합니다. 다시 사용할 수 없게하고 사용자에 대한 잠금에 대한 정보를 표시해야합니다.

private final BroadcastReceiver mReceiver = new BroadcastReceiver() { 
    @Override 
    public void onReceive(Context context, Intent intent) { 
     final String action = intent.getAction(); 

     if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) { 
      final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, 
               BluetoothAdapter.ERROR); 
      switch (state) { 
      case BluetoothAdapter.STATE_OFF: 
       //do nothing 
       break; 
      case BluetoothAdapter.STATE_TURNING_OFF: 
       //do nothing 
       break; 
      case BluetoothAdapter.STATE_ON: 
       //disable it 
       break; 
      case BluetoothAdapter.STATE_TURNING_ON: 
       //do nothing 
       break; 
      } 
     } 
    } 
}; 

이 조금 해키이지만, 이것은 당신이 할 수있는 최선입니다 - 내가 설정 별도의 응용 프로그램이며, 당신이 그것을 수정할 수 없기 때문에 이전처럼, 설정에서이 스위치를 사용하지 않도록 할 수있는 방법이 없습니다 썼다처럼 다른 응용 프로그램은 응용 프로그램을 수정할 수 없습니다.

+0

답장을 보내 주셔서 감사합니다. 하지만 사용자가 일부 앱을 잠글 수있는 앱 잠금과 같은 앱을 만들려고합니다. Applock 앱에서 블루투스, 카메라를 선택하고 비밀번호로 잠글 수 있습니다. 그래서 응용 프로그램을 잠글 수 있습니다. 어떤 제안? –

+0

답을 업데이트했습니다. – Nuwisam

+0

오케이. 알았다. 답변을 주셔서 대단히 감사합니다. i는 동일하게 구현하고 여기에서 업데이트 할 것입니다. –