SDL: show Marshmallow permission dialog for recording audio
Updated SuperTux
This commit is contained in:
@@ -37,7 +37,8 @@ import android.media.MediaRecorder.AudioSource;
|
||||
import java.io.*;
|
||||
import android.util.Log;
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
|
||||
class AudioThread
|
||||
@@ -166,6 +167,16 @@ class AudioThread
|
||||
|
||||
private byte[] startRecording(int rate, int channels, int encoding, int bufsize)
|
||||
{
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M)
|
||||
{
|
||||
int permissionCheck = mParent.checkSelfPermission(Manifest.permission.RECORD_AUDIO);
|
||||
if (permissionCheck != PackageManager.PERMISSION_GRANTED)
|
||||
{
|
||||
mParent.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, 0);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if( mRecordThread == null )
|
||||
{
|
||||
mRecordThread = new RecordingThread();
|
||||
@@ -199,8 +210,26 @@ class AudioThread
|
||||
mRecorder = new AudioRecord(AudioSource.VOICE_CALL, rate, channelConfig, encodingConfig, minBufferSize);
|
||||
mRecorderBufferSize = minBufferSize;
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.i("SDL", "SDL: error: failed to open recording device!");
|
||||
return null;
|
||||
Log.i("SDL", "SDL: error: failed to open VOICE_CALL recording device!");
|
||||
try {
|
||||
mRecorder = new AudioRecord(AudioSource.VOICE_UPLINK, rate, channelConfig, encodingConfig, minBufferSize);
|
||||
mRecorderBufferSize = minBufferSize;
|
||||
} catch (IllegalArgumentException ee) {
|
||||
Log.i("SDL", "SDL: error: failed to open VOICE_UPLINK recording device!");
|
||||
try {
|
||||
mRecorder = new AudioRecord(AudioSource.VOICE_RECOGNITION, rate, channelConfig, encodingConfig, minBufferSize);
|
||||
mRecorderBufferSize = minBufferSize;
|
||||
} catch (IllegalArgumentException eee) {
|
||||
Log.i("SDL", "SDL: error: failed to open VOICE_RECOGNITION recording device!");
|
||||
try {
|
||||
mRecorder = new AudioRecord(AudioSource.DEFAULT, rate, channelConfig, encodingConfig, minBufferSize);
|
||||
mRecorderBufferSize = minBufferSize;
|
||||
} catch (IllegalArgumentException eeee) {
|
||||
Log.i("SDL", "SDL: error: failed to open DEFAULT recording device!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -93,6 +93,8 @@ import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import java.util.TreeSet;
|
||||
import android.app.UiModeManager;
|
||||
import android.Manifest;
|
||||
|
||||
|
||||
public class MainActivity extends Activity
|
||||
{
|
||||
@@ -1490,6 +1492,20 @@ public class MainActivity extends Activity
|
||||
setRequestedOrientation(Globals.HorizontalOrientation ? ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults)
|
||||
{
|
||||
if (permissions.length == 0 || grantResults.length == 0)
|
||||
{
|
||||
Log.i("SDL", "libSDL: Permission request dialog was aborted");
|
||||
return;
|
||||
}
|
||||
if (Manifest.permission.RECORD_AUDIO.equals(permissions[0]))
|
||||
{
|
||||
Log.i("SDL", "libSDL: Record audio permission: " + (grantResults[0] == PackageManager.PERMISSION_GRANTED ? "GRANTED" : "DENIED"));
|
||||
}
|
||||
}
|
||||
|
||||
public FrameLayout getVideoLayout() { return _videoLayout; }
|
||||
|
||||
DemoGLSurfaceView mGLView = null;
|
||||
|
||||
Reference in New Issue
Block a user