Reputation: 1
private void toggleScreenShare(View v) {
ToggleButton toggleButton=(ToggleButton) v;
if(toggleButton.isChecked()){
initRecorder();
recordScreen();
}
else {
mMediaRecorder.stop();
mMediaRecorder.reset();
stopRecordScreen();
mVideoView.setVisibility(View.VISIBLE);
mVideoView.setVideoURI(Uri.parse(mVideoUrl));
mVideoView.start();
}
}
private void recordScreen() {
if(mediaProjection==null){
** startActivityForResult(mMediaProjectionManager.createScreenCaptureIntent(),REQUEST_CODE);**
return;
}
mVirtualDisplay=createVirtualDisplay();
mMediaRecorder.start();
}
This is my code I want to use onActivityResult in bold line because StartActivityFOrResult is deprecated ,Can anyone help me how to write this
I'm try many times and want the code
Upvotes: 0
Views: 89
Reputation: 211
This part of the code, will get you the result of the intent.
/**
* In your activity
* this will get you the result from the other intent.
* I do not know, what exactly you are exactly doing there.
* So you no longer need technically the request code.
*/
private final ActivityResultLauncher<Intent> yourLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
Intent intentData = result.getData();
if (intentData == null) return;
intentData.getBooleanExtra("BOOLEAN", false);
}
});
This part of the code will call your launcher with your wanted intent.
yourLauncher.launch(mMediaProjectionManager.createScreenCaptureIntent());
Hopefully this simple example enlightens the method.
Upvotes: 0