Last active
October 17, 2018 18:58
-
-
Save mtsahakis/5c709bbd9cf5074a377e6e3114c0e4b6 to your computer and use it in GitHub Desktop.
Demo Activity for https://github.com/mtsahakis/MediaProjectionDemo/issues/7 that calls https://gist.github.com/mtsahakis/a4dca46b80cb8ac2cd100a7a52f65b1d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mtsahakis.mediaprojectiondemo; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.media.projection.MediaProjectionManager; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.Button; | |
public class ScreenCaptureActivity extends Activity { | |
private static final int REQUEST_CODE = 100; | |
/****************************************** Activity Lifecycle methods ************************/ | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// start projection | |
Button startButton = (Button)findViewById(R.id.startButton); | |
startButton.setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
startProjection(); | |
} | |
}); | |
// stop projection | |
Button stopButton = (Button)findViewById(R.id.stopButton); | |
stopButton.setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
stopProjection(); | |
} | |
}); | |
} | |
@Override | |
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | |
if (requestCode == REQUEST_CODE) { | |
if (resultCode == Activity.RESULT_OK) { | |
startService(ScreenCaptureService.getStartIntent(this, resultCode, data)); | |
} | |
} | |
} | |
/****************************************** UI Widget Callbacks *******************************/ | |
private void startProjection() { | |
MediaProjectionManager mProjectionManager = | |
(MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); | |
startActivityForResult(mProjectionManager.createScreenCaptureIntent(), REQUEST_CODE); | |
} | |
private void stopProjection() { | |
startService(ScreenCaptureService.getStopIntent(this)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment