I have an error with the runtime permissions

0

Hello friends I tell you that I have a problem, I have two buttons one allows me to access the microphone and the other save then I need two permissions, which work well to run the app leaves the sign asking for permission and all the problem is I can not use the buttons until I close and return to run the app I leave the structure I hope I get an orientation that I'm doing wrong.

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

    if (ContextCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO}, 1000);
    } else {                                    

      grabar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                    Toast.makeText(getApplicationContext(), "La grabación comenzó", Toast.LENGTH_LONG).show();
            }
        });   
    guardar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                    Toast.makeText(getApplicationContext(), "Se guardo", Toast.LENGTH_LONG).show();
            }
        });

    }
  }
    
asked by Android Facil 05.06.2018 в 00:05
source

1 answer

0

The problem is the structuring carried out. When using an "if () {} else {}" as you have stated, if the condition to access the if is correct, that is, you do not have permissions, it will no longer enter the "else" since one excludes the other. As a possible solution, you can check and grant the permissions at the beginning of the activity or directly in the manifest, and therefore define the actions of the buttons.

    
answered by 05.06.2018 в 10:36