Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Issue Android 14 compatibility #166 #167

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public Countdown(long totalTime, long interval, long delay) {

public void start() {
wasStarted = true;
this.scheduleAtFixedRate(task, delay, interval);
this.schedule(task, delay, interval);
}

public void stop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ else if (intent.getAction().equals("resume")) {
if (Build.VERSION.SDK_INT >= 31) {
pendingIntent = PendingIntent.getBroadcast(this, 0, myIntent, PendingIntent.FLAG_IMMUTABLE);
} else {
pendingIntent = PendingIntent.getBroadcast(this, 0, myIntent, 0);
pendingIntent = PendingIntent.getBroadcast(this, 0, myIntent, PendingIntent.FLAG_IMMUTABLE);

}

Expand Down Expand Up @@ -346,7 +346,7 @@ public void onInfo(MediaRecorder mr, int what, int extra) {

//Pause Recording
@RequiresApi(api = Build.VERSION_CODES.N)
private void pauseRecording(){
private void pauseRecording() {
mMediaRecorder.pause();
ResultReceiver receiver = mIntent.getParcelableExtra(ScreenRecordService.BUNDLED_LISTENER);
Bundle bundle = new Bundle();
Expand All @@ -358,7 +358,7 @@ private void pauseRecording(){

//Resume Recording
@RequiresApi(api = Build.VERSION_CODES.N)
private void resumeRecording(){
private void resumeRecording() {
mMediaRecorder.resume();
ResultReceiver receiver = mIntent.getParcelableExtra(ScreenRecordService.BUNDLED_LISTENER);
Bundle bundle = new Bundle();
Expand Down Expand Up @@ -469,12 +469,24 @@ private void setAudioSourceAsInt(String audioSource) {

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void initMediaProjection() {
mMediaProjection = ((MediaProjectionManager) Objects.requireNonNull(getSystemService(Context.MEDIA_PROJECTION_SERVICE))).getMediaProjection(mResultCode, mResultData);
mMediaProjection = ((MediaProjectionManager) Objects
.requireNonNull(getSystemService(Context.MEDIA_PROJECTION_SERVICE)))
.getMediaProjection(mResultCode, mResultData);
Handler handler = new Handler(Looper.getMainLooper());
mMediaProjection.registerCallback(new MediaProjection.Callback() {
// Nothing
// We don't use it but register it to avoid runtime error from SDK 34+.
}, handler);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
mMediaProjection.registerCallback(new MediaProjection.Callback() {
@Override
public void onStop() {
super.onStop();
}
}, handler);
} else {
mMediaProjection.registerCallback(new MediaProjection.Callback() {
// Nothing
// We don't use it but register it to avoid runtime error from SDK 34+.
}, handler);
}
}

//Return the output file path as string
Expand Down Expand Up @@ -513,7 +525,7 @@ private void initRecorder() throws Exception {
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(outputFormatAsInt);

if (orientationHint != 400){
if (orientationHint != 400) {
mMediaRecorder.setOrientationHint(orientationHint);
}

Expand All @@ -539,7 +551,7 @@ private void initRecorder() throws Exception {
receiver.send(Activity.RESULT_OK, bundle);
}
}
}else{
} else {
mMediaRecorder.setOutputFile(filePath);
}
mMediaRecorder.setVideoSize(mScreenWidth, mScreenHeight);
Expand All @@ -558,7 +570,7 @@ private void initRecorder() throws Exception {
}

// Catch approaching file limit
if ( maxFileSize > NO_SPECIFIED_MAX_SIZE) {
if (maxFileSize > NO_SPECIFIED_MAX_SIZE) {
mMediaRecorder.setMaxFileSize(maxFileSize); // in bytes
}

Expand All @@ -568,6 +580,10 @@ private void initRecorder() throws Exception {

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void initVirtualDisplay() {
if (mMediaProjection == null) {
Log.d(TAG, "initVirtualDisplay: " + " Media projection is not initialized properly.");
return;
}
mVirtualDisplay = mMediaProjection.createVirtualDisplay(TAG, mScreenWidth, mScreenHeight, mScreenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR, mMediaRecorder.getSurface(), null, null);
}

Expand All @@ -589,7 +605,7 @@ public void onDestroy() {
}

private void callOnComplete() {
if ( mIntent != null ) {
if (mIntent != null) {
ResultReceiver receiver = mIntent.getParcelableExtra(ScreenRecordService.BUNDLED_LISTENER);
Bundle bundle = new Bundle();
bundle.putString(ON_COMPLETE_KEY, ON_COMPLETE);
Expand Down