Samsung galaxy S6 edge 6.0.1 works fine, so maybe Android M is not the factor here.
First off, the Android 6.0+ permissions are given, so that's not the case .
Here it is :
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){ //нужно проверять пермишны if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CAMERA,Manifest.permission.RECORD_AUDIO,Manifest.permission.INTERNET,Manifest.permission.ACCESS_NETWORK_STATE,Manifest.permission.READ_EXTERNAL_STORAGE,Manifest.permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST); } }
I've tested my app on other devices and it works fine, but on Nexus 5 (hammerhead) I've got an error when MediaRecorder.start() is called and I don't know much what to do with that.
The stacktrace is as simple as :
java.lang.RuntimeException: start failed. at android.media.MediaRecorder.start(Native Method) at com.vladdrummer.headsup.ScreenVideoRecorder.record(ScreenVideoRecorder.java:94)
So, not too much info. Here's the code, but keep in mind , it Works on other devices
private Camera camera; ... camera.setPreviewDisplay(holder); camera.startPreview(); isPrepared = prepareVideoRecorder(); .. private boolean prepareVideoRecorder() { try{ camera.unlock(); mediaRecorder = new MediaRecorder(); mediaRecorder.setCamera(camera); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); mediaRecorder.setProfile(CamcorderProfile .get(CamcorderProfile.QUALITY_HIGH)); String path = A.getRawGameVideoPath();//4 debug purposes mediaRecorder.setOutputFile(path); mediaRecorder.setPreviewDisplay(surfaceView.getHolder().getSurface()); } catch (Exception e){ e.printStackTrace(); return false; } try { mediaRecorder.prepare(); } catch (Exception e) { e.printStackTrace(); release(); return false; } return true; } public void record(){ if (isPrepared){ mediaRecorder.start(); // Here where it crashes on Android M } }
Of course, it may be crashing on other devices as well, I tested it on 3 devices only