Simplified permission request code

This commit is contained in:
Pierre HUBERT 2019-02-28 18:47:52 +01:00
parent 7ad41b1754
commit ed46ea9cea

View File

@ -31,6 +31,7 @@ import org.communiquons.android.comunic.client.ui.asynctasks.HangUpCallTask;
import org.communiquons.android.comunic.client.ui.asynctasks.RespondToCallTask; import org.communiquons.android.comunic.client.ui.asynctasks.RespondToCallTask;
import org.communiquons.android.comunic.client.ui.models.CallPeerConnection; import org.communiquons.android.comunic.client.ui.models.CallPeerConnection;
import org.communiquons.android.comunic.client.ui.receivers.PendingCallsBroadcastReceiver; import org.communiquons.android.comunic.client.ui.receivers.PendingCallsBroadcastReceiver;
import org.communiquons.android.comunic.client.ui.utils.PermissionsUtils;
import org.communiquons.android.comunic.client.ui.utils.UiUtils; import org.communiquons.android.comunic.client.ui.utils.UiUtils;
import org.communiquons.signalexchangerclient.SignalExchangerCallback; import org.communiquons.signalexchangerclient.SignalExchangerCallback;
import org.communiquons.signalexchangerclient.SignalExchangerClient; import org.communiquons.signalexchangerclient.SignalExchangerClient;
@ -73,8 +74,6 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac
/** /**
* Permissions requests codes * Permissions requests codes
*/ */
private static final int MY_PERMISSIONS_REQUEST_CAMERA = 100;
private static final int MY_PERMISSIONS_REQUEST_RECORD_AUDIO = 101;
private static final int MY_PERMISSIONS_REQUEST = 102; private static final int MY_PERMISSIONS_REQUEST = 102;
/** /**
@ -178,25 +177,12 @@ public class CallActivity extends BaseActivity implements SignalExchangerCallbac
* Based on https://github.com/sergiopaniego/WebRTCAndroidExample * Based on https://github.com/sergiopaniego/WebRTCAndroidExample
*/ */
private void askForPermissions() { private void askForPermissions() {
if ((ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) &&
(ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED)) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO},
MY_PERMISSIONS_REQUEST);
} else if (ContextCompat.checkSelfPermission(this,
Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.RECORD_AUDIO},
MY_PERMISSIONS_REQUEST_RECORD_AUDIO);
} else if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) PermissionsUtils.RequestPermissions(this, new String[]{
!= PackageManager.PERMISSION_GRANTED) { Manifest.permission.CAMERA,
ActivityCompat.requestPermissions(this, Manifest.permission.RECORD_AUDIO
new String[]{Manifest.permission.CAMERA}, }, MY_PERMISSIONS_REQUEST);
MY_PERMISSIONS_REQUEST_CAMERA);
}
} }
/** /**