title: Request permissions in main activity
body: <p>I have an application which records and stores audio on the device. My main activity contains a bunch of buttons to other activities. These other activities are the ones that do the actual audio recording. </p>
  
  <p>My main activity is set up as follows:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  
      private Button mSmallVowel;
      private Button mSayCat;
      private Button mCough;
      private Button mSaySentence;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          String sep = File.separator;
          String newFolder = "AudioRecordingTest";
          String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
          File myNewFolder = new File(extStorageDirectory + sep + newFolder);
          myNewFolder.mkdir();
  
          mSmallVowel = (Button) findViewById(R.id.btnSmallVowel);
          mSmallVowel.setOnClickListener(this);
          mSayCat = (Button) findViewById(R.id.btnSayCat);
          mSayCat.setOnClickListener(this);
          mCough = (Button) findViewById(R.id.btnCough);
          mCough.setOnClickListener(this);
          mSaySentence = (Button) findViewById(R.id.btnSaySentence);
          mSaySentence.setOnClickListener(this);
      }
  
      @Override
      public void onClick(View v) {
          switch(v.getId()) {
              case R.id.btnSmallVowel:
                  Intent small_vowel_intent = new Intent(this, SmallVowel.class);
                  this.startActivity(small_vowel_intent);
                  break;
              case R.id.btnSayCat:
                  Intent say_cat_intent = new Intent(this, SayCat.class);
                  this.startActivity(say_cat_intent);
                  break;
              case R.id.btnCough:
                  Intent cough_intent = new Intent(this, Cough.class);
                  this.startActivity(cough_intent);
                  break;
              case R.id.btnSaySentence:
                  Intent say_sentence_intent = new Intent(this, SaySentence.class);
                  this.startActivity(say_sentence_intent);
                  break;
          }
      }
  }
  </code></pre>
  
  <p>And all the other activities look like the following:</p>
  
  <pre><code>public class SaySentence extends AppCompatActivity {
  
      private MediaRecorder recorder;
      private String OUTPUT_FILE;
      private TextView mStatus;
      private TextView mRecorded;
  
      //folder initialization
      private String sep = File.separator;
      private String mChildFolder = "SaySentence";
      private String mExtStorageDirectory = Environment.getExternalStorageDirectory().toString();
      private File mChildFile = new File(mExtStorageDirectory + sep + "AudioRecordingTest" + sep + mChildFolder);
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_say_sentence);
  
          mChildFile.mkdir();
  
          mStatus = (TextView) findViewById(R.id.txtStatus);
          mRecorded = (TextView) findViewById(R.id.txtRecorded);
  
      }
  
      public void startSpeaking(View view) {
          //clear text
          mRecorded.setText("");
  
          try {
              beginRecording();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      public void stopSpeaking(View view) {
          try {
              stopRecording();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      private void beginRecording() {
          ditchMediaRecorder();
  
          //get number of files already in sub-folder and increment the audio filename accordingly
          File[] filesInFolder = mChildFile.listFiles();
          if (filesInFolder != null) {
              int count = filesInFolder.length;
              OUTPUT_FILE = mExtStorageDirectory + sep + "AudioRecordingTest" + sep + mChildFolder + sep + "saysentence" + (count+1) + ".3gpp";
          }
          else {
              OUTPUT_FILE = mExtStorageDirectory + sep + "AudioRecordingTest" + sep + mChildFolder + sep + "saysentence0" + ".3gpp";
          }
  
          File outFile = new File(OUTPUT_FILE);
  
          mStatus.setText("Recording");
  
          if(outFile.exists()){
              outFile.delete();
          }
  
          recorder = new MediaRecorder();
          recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
          recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
          recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
          recorder.setOutputFile(OUTPUT_FILE);
  
          try {
              recorder.prepare();
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          recorder.start();
  
      }
  
      private void stopRecording() {
          mStatus.setText("Recording Stopped");
          mRecorded.setText("Audio file saved to: " + OUTPUT_FILE);
  
          if(recorder != null){
              recorder.stop();
          }
  
      }
  
      private void ditchMediaRecorder() {
          if(recorder != null) {
              recorder.release();
          }
      }
  }
  </code></pre>
  
  <p>Since in Android 6.0 permissions have to be asked at run time, I would like to make it so that the main activity requests all the permissions I require in my manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.soufinrahimeen.audiorecordingtest"&gt;
  
      &lt;uses-permission android:name="android.permission.RECORD_AUDIO" /&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher_medical"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
          &lt;activity android:name=".SmallVowel" /&gt;
          &lt;activity android:name=".SayCat" /&gt;
          &lt;activity android:name=".Cough" /&gt;
          &lt;activity android:name=".SaySentence"&gt;&lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt; 
  </code></pre>
  
  <p>I have looked at the official docs on <a href="https://developer.android.com/training/permissions/requesting.html" rel="nofollow noreferrer">Requesting Permissions at Run Time</a>, however, the official tutorial makes it seem like I need to ask for permissions in the activities that actually record and save the audio.</p>
  
  <p>I would like to make it so that the MainActivity requests all the required permissions, and once the user enables them, it allows them to use the rest of the application without any issue.</p>
  
  <p>How can I achieve this?</p>