Estoy realizando una App en donde desde una actividad tengo 4 Switch, por cada Switch quiero que por ejemplo, cuando el Switch esté activado al momento de ir a mi cámara, no me permita acceder a ella y así con las demás opciones, digamos que los permisos se vendrían manejando a nivel administrador del dispositivo.
Camara.
Wi-fi.
Play store.
Notificaciones.
Mi pregunta es ¿Cómo puedo bloquear estos permisos del dispositivo desde mi App? no encuentro mucha información al respecto.
Así sería mi idea.
Código para negar el acceso a la cámara:
public class enrolar_ws extends AppCompatActivity {
ComponentName mDeviceAdminRcvr;
DevicePolicyManager activeDevicePolicyManager;
private SharedPreferences pf_configuracion;
private SharedPreferences.Editor editor;
private Switch sw_camara;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enrolar);
sw_camara=(Switch)findViewById(R.id.sw_camara);
pf_configuracion=getSharedPreferences("configuracion", Context.MODE_PRIVATE);
editor=pf_configuracion.edit();
activeDevicePolicyManager = (DevicePolicyManager)getSystemService(Context.DEVICE_POLICY_SERVICE);
mDeviceAdminRcvr = new ComponentName(this, addeviceReceiver.class);
if(pf_configuracion.getString("camara","").equals("0")){
sw_camara.setChecked(false);
if (activeDevicePolicyManager.isAdminActive(mDeviceAdminRcvr)) {
activeDevicePolicyManager.setCameraDisabled(mDeviceAdminRcvr, false);
} else {
Intent intent2 = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent2.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminRcvr);
startActivityForResult(intent2,1);
}
}else{
sw_camara.setChecked(true);
if (activeDevicePolicyManager.isAdminActive(mDeviceAdminRcvr)) {
activeDevicePolicyManager.setCameraDisabled(mDeviceAdminRcvr, true);
} else {
Intent intent2 = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent2.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminRcvr);
startActivityForResult(intent2,1);
}
}
sw_camara.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(sw_camara.isChecked()){
sw_camara.setChecked(true);
editor.putString("camara","1");
editor.commit();
sw_camara.setChecked(true);
if (activeDevicePolicyManager.isAdminActive(mDeviceAdminRcvr)) {
activeDevicePolicyManager.setCameraDisabled(mDeviceAdminRcvr, true);
} else {
Intent intent2 = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent2.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminRcvr);
startActivityForResult(intent2,1);
}
}else{
sw_camara.setChecked(false);
editor.putString("camara","0");
editor.commit();
if (activeDevicePolicyManager.isAdminActive(mDeviceAdminRcvr)) {
activeDevicePolicyManager.setCameraDisabled(mDeviceAdminRcvr, false);
} else {
Intent intent2 = new Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN);
intent2.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mDeviceAdminRcvr);
startActivityForResult(intent2,1);
}
}
}
});
}
}