本文整理匯總了Java中android.media.projection.MediaProjectionManager.getMediaProjection方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaProjectionManager.getMediaProjection方法的具體用法?Java MediaProjectionManager.getMediaProjection怎麽用?Java MediaProjectionManager.getMediaProjection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.media.projection.MediaProjectionManager
的用法示例。
在下文中一共展示了MediaProjectionManager.getMediaProjection方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onActivityResult
import android.media.projection.MediaProjectionManager; //導入方法依賴的package包/類
@Override
@TargetApi(21)
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE && resultCode == Activity.RESULT_OK) {
String uri = data.toUri(0);
MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(Activity.MEDIA_PROJECTION_SERVICE);
MediaProjection mediaProjection = projectionManager.getMediaProjection(resultCode, data);
ScreenCaptureService.setMediaProjection(mediaProjection);
startService(new Intent(ScreenCaptureService.ACTION_START, null, this, ScreenCaptureService.class));
fab.setSelected(true);
}
if (requestCode == REQUEST_CODE_MAKE_SMING && resultCode == RESULT_OK) {
loadSmings();
checkEmpty();
}
}
示例2: onActivityResult
import android.media.projection.MediaProjectionManager; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.M)
@Override
/**
* Called when another activity has sent a result to this activity. For example when this activity starts the
* activity which calls for the projectionmanager, which tells this class if the screen capture has been enabled.
*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == OVERLAY_PERMISSION_REQ_CODE) {
updateLaunchButtonText(false);
} else if (requestCode == SCREEN_CAPTURE_REQ_CODE) {
if (resultCode == RESULT_OK) {
MediaProjectionManager projectionManager = (MediaProjectionManager) getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
MediaProjection mProjection = projectionManager.getMediaProjection(resultCode, data);
screen = ScreenGrabber.init(mProjection, rawDisplayMetrics);
startPokeFly();
} else {
updateLaunchButtonText(false);
}
}
}
示例3: onActivityResult
import android.media.projection.MediaProjectionManager; //導入方法依賴的package包/類
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String ip = mReceiverIpEditText.getText().toString();
final SharedPreferences sharedPreferences = getSharedPreferences(PREF_NAME, 0);
final SharedPreferences.Editor edit = sharedPreferences.edit();
edit.putString(RECEIVER_IP_KEY,ip);
edit.commit();
if(resultCode == RESULT_OK && requestCode==GET_MEDIA_PROJECTION_CODE){
try {
@SuppressWarnings("ResourceType") MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
final MediaProjection mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, data);
mEncoderAsyncTask = new EncoderAsyncTask(this, mediaProjection, mMediaCodecFactory);
mEncoderAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
mSenderAsyncTask = new SenderAsyncTask(ip);
mSenderAsyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} catch (IOException e) {
mStartButton.setEnabled(false);
mStartButton.setText(getString(R.string.mediacodec_error));
e.printStackTrace();
}
}
}
示例4: startRecording
import android.media.projection.MediaProjectionManager; //導入方法依賴的package包/類
private void startRecording() {
//Initialize MediaRecorder class and initialize it with preferred configuration
mMediaRecorder = new MediaRecorder();
initRecorder();
//Set Callback for MediaProjection
mMediaProjectionCallback = new MediaProjectionCallback();
MediaProjectionManager mProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
//Initialize MediaProjection using data received from Intent
mMediaProjection = mProjectionManager.getMediaProjection(result, data);
mMediaProjection.registerCallback(mMediaProjectionCallback, null);
/* Create a new virtual display with the actual default display
* and pass it on to MediaRecorder to start recording */
mVirtualDisplay = createVirtualDisplay();
try {
mMediaRecorder.start();
//If floating controls is enabled, start the floating control service and bind it here
if (useFloatingControls) {
Intent floatinControlsIntent = new Intent(this, FloatingControlService.class);
startService(floatinControlsIntent);
bindService(floatinControlsIntent,
serviceConnection, BIND_AUTO_CREATE);
}
//Set the state of the recording
if (isBound)
floatingControlService.setRecordingState(Const.RecordingState.RECORDING);
isRecording = true;
//Send a broadcast receiver to the plugin app to enable show touches since the recording is started
if (showTouches) {
Intent TouchIntent = new Intent();
TouchIntent.setAction("com.orpheusdroid.screenrecorder.SHOWTOUCH");
TouchIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(TouchIntent);
}
Toast.makeText(this, R.string.screen_recording_started_toast, Toast.LENGTH_SHORT).show();
} catch (IllegalStateException e) {
Log.d(Const.TAG, "Mediarecorder reached Illegal state exception. Did you start the recording twice?");
Toast.makeText(this, R.string.recording_failed_toast, Toast.LENGTH_SHORT).show();
isRecording = false;
}
/* Add Pause action to Notification to pause screen recording if the user's android version
* is >= Nougat(API 24) since pause() isnt available previous to API24 else build
* Notification with only default stop() action */
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
//startTime is to calculate elapsed recording time to update notification during pause/resume
startTime = System.currentTimeMillis();
Intent recordPauseIntent = new Intent(this, RecorderService.class);
recordPauseIntent.setAction(Const.SCREEN_RECORDING_PAUSE);
PendingIntent precordPauseIntent = PendingIntent.getService(this, 0, recordPauseIntent, 0);
NotificationCompat.Action action = new NotificationCompat.Action(android.R.drawable.ic_media_pause,
getString(R.string.screen_recording_notification_action_pause), precordPauseIntent);
//Start Notification as foreground
startNotificationForeGround(createRecordingNotification(action).build(), Const.SCREEN_RECORDER_NOTIFICATION_ID);
} else
startNotificationForeGround(createRecordingNotification(null).build(), Const.SCREEN_RECORDER_NOTIFICATION_ID);
}
示例5: getProjection
import android.media.projection.MediaProjectionManager; //導入方法依賴的package包/類
public MediaProjection getProjection(MediaProjectionManager manager) {
return manager.getMediaProjection(resultCode, projectionIntent);
}
示例6: initVirtualDisplay
import android.media.projection.MediaProjectionManager; //導入方法依賴的package包/類
private void initVirtualDisplay(MediaProjectionManager manager, Intent data, int screenWidth, int screenHeight, int screenDensity) {
mImageReader = ImageReader.newInstance(screenWidth, screenHeight, PixelFormat.RGBA_8888, 1);
mMediaProjection = manager.getMediaProjection(Activity.RESULT_OK, data);
mVirtualDisplay = mMediaProjection.createVirtualDisplay("screen-mirror",
screenWidth, screenHeight, screenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
mImageReader.getSurface(), null, null);
}
示例7: initScreenManager
import android.media.projection.MediaProjectionManager; //導入方法依賴的package包/類
private void initScreenManager() {
L.d("初始化錄屏。。。");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mMediaProjectionManager = (MediaProjectionManager)
getSystemService(Context.MEDIA_PROJECTION_SERVICE);
mMediaProjection = mMediaProjectionManager.getMediaProjection(Activity.RESULT_OK,
mCapturePermissionIntent);
}
startDisplayManager();
new Thread(new EncoderWorker()).start();
}
示例8: initVirtualDisplay
import android.media.projection.MediaProjectionManager; //導入方法依賴的package包/類
private void initVirtualDisplay(MediaProjectionManager manager, Intent data, int screenWidth, int screenHeight, int screenDensity) {
mImageReader = ImageReader.newInstance(screenWidth, screenHeight, PixelFormat.RGBA_8888, 2);
mMediaProjection = manager.getMediaProjection(Activity.RESULT_OK, data);
mVirtualDisplay = mMediaProjection.createVirtualDisplay("screen-mirror",
screenWidth, screenHeight, screenDensity, DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR,
mImageReader.getSurface(), null, null);
}
示例9: setProjectionData
import android.media.projection.MediaProjectionManager; //導入方法依賴的package包/類
public void setProjectionData(Intent data) {
MediaProjectionManager mediaProjectionManager =
(MediaProjectionManager) context.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
mediaProjection = mediaProjectionManager.getMediaProjection(Activity.RESULT_OK, data);
if (mediaProjection != null) {
//disable callback as it doesn't work anyways
//mediaProjection.registerCallback(mediaProjectionCallback, handler);
if (getState() == RecordingProcessState.STARTING) {
start(file, null);
} else {
setState(RecordingProcessState.READY, null);
}
}
}
示例10: onActivityResult
import android.media.projection.MediaProjectionManager; //導入方法依賴的package包/類
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.v(TAG,"onActivityResult");
if(requestCode!=CAPTURE_CODE){
Log.e(TAG,"onActivityResult : requestCode!=CAPTURE_CODE");
return;
}
if (resultCode != RESULT_OK) {
Log.e(TAG,"onActivityResult : resultCode != RESULT_OK");
mMediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
startActivityForResult(mMediaProjectionManager.createScreenCaptureIntent(), CAPTURE_CODE);
}
mMediaProjection = mMediaProjectionManager.getMediaProjection(resultCode,data);
session.setMediaProjection(mMediaProjection);
InitCameraView();
}