本文整理匯總了Java中android.media.projection.MediaProjectionManager類的典型用法代碼示例。如果您正苦於以下問題:Java MediaProjectionManager類的具體用法?Java MediaProjectionManager怎麽用?Java MediaProjectionManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MediaProjectionManager類屬於android.media.projection包,在下文中一共展示了MediaProjectionManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: createVirtualEnvironment
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void createVirtualEnvironment() {
dateFormat = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");
strDate = dateFormat.format(new java.util.Date());
pathImage = Environment.getExternalStorageDirectory().getPath() + "/Pictures/";
nameImage = pathImage + strDate + ".png";
mMediaProjectionManager1 = (MediaProjectionManager) activity.getApplication().getSystemService(Context.MEDIA_PROJECTION_SERVICE);
mWindowManager1 = (WindowManager) activity.getApplication().getSystemService(Context.WINDOW_SERVICE);
windowWidth = ViewUtil.getScreenWidth(activity);
windowHeight = ViewUtil.getSceenHeight(activity);
metrics = new DisplayMetrics();
mWindowManager1.getDefaultDisplay().getMetrics(metrics);
mScreenDensity = metrics.densityDpi;
mImageReader = ImageReader.newInstance(windowWidth, windowHeight, 0x1, 2); //ImageFormat.RGB_565
LogUtil.d(TAG, "prepared the virtual environment");
}
示例3: onReceive
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(ScreenCapture.ASSISTANT_ACTIVITY_CREATED_INTENT)) {
ScreenCapture screenCapture = mSender;
if (ScreenCapture.mScreenCaptureActivity != null) {
ScreenCapture.ScreenCaptureAssistantActivity screenActivity =
ScreenCapture.mScreenCaptureActivity;
ScreenCapture.mScreenCaptureActivity.mScreenCapture = screenCapture;
if (screenActivity.mScreenCapture.mMediaProjectManager == null) {
screenActivity.mScreenCapture.mMediaProjectManager =
(MediaProjectionManager) screenActivity.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
}
screenActivity.startActivityForResult(
screenActivity.mScreenCapture.mMediaProjectManager.createScreenCaptureIntent(),
ScreenCapture.MEDIA_PROJECTION_REQUEST_CODE);
}
}
}
示例4: initialize
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
@Override
public synchronized void initialize(final SurfaceTextureHelper surfaceTextureHelper,
final Context applicationContext, final VideoCapturer.CapturerObserver capturerObserver) {
checkNotDisposed();
if (capturerObserver == null) {
throw new RuntimeException("capturerObserver not set.");
}
this.capturerObserver = capturerObserver;
if (surfaceTextureHelper == null) {
throw new RuntimeException("surfaceTextureHelper not set.");
}
this.surfaceTextureHelper = surfaceTextureHelper;
mediaProjectionManager = (MediaProjectionManager) applicationContext.getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
}
示例5: onActivityCreated
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Activity activity = getActivity();
DisplayMetrics metrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
mDensity = metrics.densityDpi;
mMediaProjectionManager = (MediaProjectionManager)
activity.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
//run permissions
startActivityForResult(
mMediaProjectionManager.createScreenCaptureIntent(),
REQUEST_MEDIA_PROJECTION);
}
示例6: onCreate
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
/****************************************** Activity Lifecycle methods ************************/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_screen_short);
// call for the projection manager
mProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
startProjection();
// start capture handling thread
new Thread() {
@Override
public void run() {
Looper.prepare();
mHandler = new Handler();
Looper.loop();
}
}.start();
}
示例7: onCreate
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blank);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
mScreenDensity = metrics.densityDpi;
mMediaRecorder = new MediaRecorder();
initRecorder();
prepareRecorder();
mProjectionManager = (MediaProjectionManager) getSystemService
(Context.MEDIA_PROJECTION_SERVICE);
mToggleButton = (ToggleButton) findViewById(R.id.toggle);
mToggleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onToggleScreenShare(v);
}
});
mMediaProjectionCallback = new MediaProjectionCallback();
}
示例8: requestMediaProjection
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
public void requestMediaProjection() {
boolean permanent = Utils.isMediaProjectionPermanent(this);
boolean affectedVersion = Build.VERSION.RELEASE.equals("5.1") || Build.VERSION.RELEASE.equals("5.1.0");
if (affectedVersion && permanent && !getSharedPreferences(PREFERENCES_NAME, 0).getBoolean(SYSTEM_UI_CRASH_MESSAGE, false)) {
getSharedPreferences(PREFERENCES_NAME, 0).edit().putBoolean(SYSTEM_UI_CRASH_MESSAGE, true).apply();
new SystemUICrashDialogFragment().show(getFragmentManager(), SystemUICrashDialogFragment.FRAGMENT_TAG);
} else {
if (affectedVersion && !permanent) {
Toast.makeText(this, getString(R.string.system_ui_crash_warning_toast, getString(R.string.media_projection_remember_text)), Toast.LENGTH_SHORT).show();
}
MediaProjectionManager mediaProjectionManager =
(MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
startActivityForResult(mediaProjectionManager.createScreenCaptureIntent(),
PERMISSION_CODE);
}
}
示例9: showDialog
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
@Override
public boolean showDialog() {
try {
Activity currentActivity = getActivity();
final FragmentManager fm = ((FragmentActivity) currentActivity).getSupportFragmentManager();
if (!isAttachedToWindow()
|| (fm.findFragmentByTag(CONTROLLER_TAG) != null)
|| (fm.findFragmentByTag(CHOOSER_TAG) != null) ) {
return false;
}
MediaRouter.RouteInfo route = getMediaRouter().getSelectedRoute();
if (route.isDefault() || !route.matchesSelector(mSelector)) { // route chooser
Intent intent = ((MediaProjectionManager)
currentActivity.getSystemService(Context.MEDIA_PROJECTION_SERVICE)).createScreenCaptureIntent();
currentActivity.startActivityForResult(intent, CastScreenActivity.SCREEN_CAPTURE_REQUEST);
return true;
} else { // route controller
return super.showDialog();
}
} catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
Log.e(TAG, "MediaRouteButton implementation changed - " + CastScreenActivity.PLEASE_REPORT_BUG);
}
return false;
}
示例10: ProjectionManager
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
public ProjectionManager(Context context, DisplayMetrics metrics,
int permissionsResultCode, Intent permissionsData, final MediaRouter router) {
mDensity = metrics.densityDpi;
mProjection = ((MediaProjectionManager) context.getSystemService(Context.MEDIA_PROJECTION_SERVICE))
.getMediaProjection(permissionsResultCode, permissionsData);
if (mProjection == null) {
throw new IllegalStateException("Null media projection manager - " + CastScreenActivity.PLEASE_REPORT_BUG);
}
// When the MediaProjection is stopped, deselect the active route to ensure casting stops
mProjection.registerCallback(new MediaProjection.Callback() {
@Override
public void onStop() {
router.selectRoute(router.getDefaultRoute());
}
}, null);
}
示例11: 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);
}
}
}
示例12: onStartCommand
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
@Override
public int onStartCommand(Intent intent, int flags, int startId){
Log.d(TAG, "onStartCommand");
mHandler = new MainServiceHandler(this);
mIntent = (Intent) intent.getExtras().get(EXTRA_RESULT_INTENT);
mResultCode = intent.getExtras().getInt(EXTRA_RESULT_CODE);
mMediaProjectionManager = (MediaProjectionManager) getSystemService(MEDIA_PROJECTION_SERVICE);
if (mCaptureWindow == null){
mCaptureWindow = new CaptureWindow(this);
}
else {
mCaptureWindow.reInit();
}
return START_NOT_STICKY;
}
示例13: allocate
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
@CalledByNative
public boolean allocate(int width, int height) {
mWidth = width;
mHeight = height;
mMediaProjectionManager =
(MediaProjectionManager) ContextUtils.getApplicationContext().getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
if (mMediaProjectionManager == null) {
Log.e(TAG, "mMediaProjectionManager is null");
return false;
}
WindowManager windowManager =
(WindowManager) ContextUtils.getApplicationContext().getSystemService(
Context.WINDOW_SERVICE);
mDisplay = windowManager.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
mDisplay.getMetrics(metrics);
mScreenDensity = metrics.densityDpi;
return true;
}
示例14: onActivityCreated
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
if (DEBUG) Log.d(TAG, "ScreenCaptureFragment.onActivityCreated enabled=" + enabled + ", mVirtualDisplay=" + mVirtualDisplay);
Activity activity = getActivity();
DisplayMetrics mDisplayMetrics = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(mDisplayMetrics);
mScreenDensity = mDisplayMetrics.densityDpi;
mScreenWidth = mDisplayMetrics.widthPixels;
mScreenHeight = mDisplayMetrics.heightPixels;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mMediaProjectionManager = (MediaProjectionManager) activity.getSystemService(Context.MEDIA_PROJECTION_SERVICE);
}
else {
; // TODO
}
mMediaRecorder = new MediaRecorder();
if (enabled && mVirtualDisplay == null) {
go();
}
}
示例15: onCreate
import android.media.projection.MediaProjectionManager; //導入依賴的package包/類
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.media_projection);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
mScreenDensity = metrics.densityDpi;
mSurfaceView = (SurfaceView) findViewById(R.id.surface);
mSurface = mSurfaceView.getHolder().getSurface();
mProjectionManager =
(MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
ArrayAdapter<Resolution> arrayAdapter = new ArrayAdapter<Resolution>(
this, android.R.layout.simple_list_item_1, RESOLUTIONS);
Spinner s = (Spinner) findViewById(R.id.spinner);
s.setAdapter(arrayAdapter);
s.setOnItemSelectedListener(new ResolutionSelector());
s.setSelection(0);
}