title: I2S1 error: Cannot read from output-only device (Operation not permitted) (code 1)
body: <p>I'm kind of new to Android I'm working</p>
  
  <ol>
  <li>mostly on i2s adafruit microphone</li>
  <li>also on typical USB microphone
  with Android things on Raspberry pi.</li>
  </ol>
  
  <p>Android documentation says it supports USB mic since Preview 2, but I couldn't find any example.</p>
  
  <p><a href="https://developer.android.com/things/preview/releases.html" rel="nofollow noreferrer">https://developer.android.com/things/preview/releases.html</a></p>
  
  <p>So I'm on i2s microphone for now and stuck here.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>// I2S Device Name
  private static final String I2S_DEVICE_NAME = "I2S1";
  
  private static final AudioFormat AUDIO_FORMAT_STEREO =
          new AudioFormat.Builder()
                  .setChannelMask(AudioFormat.CHANNEL_IN_STEREO)
                  .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
                  .setSampleRate(44100)
                  .build();
  
  private I2sDevice mDevice;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      String str = "";
  
      // Attempt to access the I2C device
      try {
          PeripheralManagerService manager = new PeripheralManagerService();
          mDevice = manager.openI2sDevice(I2S_DEVICE_NAME, AUDIO_FORMAT_STEREO, I2sDevice.PCM_FORMAT_16_BIT);
      } catch (IOException e) {
          Log.w(TAG, "Unable to access I2S device", e);
      }
  
      // Set up the audio playback sink
      int bufferSize = AudioTrack.getMinBufferSize(
              AUDIO_FORMAT_STEREO.getSampleRate(),
              AUDIO_FORMAT_STEREO.getChannelMask(),
              AUDIO_FORMAT_STEREO.getEncoding());
  
      str += String.valueOf(bufferSize) + "    ";
  
      // Transfer data from input to output
      ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
      try{
          int read = mDevice.read(buffer, bufferSize);
          str += String.valueOf(read);
      } catch (IOException e) {
          Log.w(TAG, "Unable to access I2S1 device", e);
      }
      TextView myText = (TextView) findViewById(R.id.mytextview);
  
      myText.setText(str);
  }
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <p>At line:</p>
  
  <pre><code>mDevice.read()
  </code></pre>
  
  <p>android monitor says</p>
  
  <blockquote>
    <p>I2S1 error: Cannot read from output-only device (Operation not
    permitted) (code 1)</p>
  </blockquote>
  
  <p>Can I get any help?</p>