List of usage examples for android.content Context MEDIA_PROJECTION_SERVICE
String MEDIA_PROJECTION_SERVICE
To view the source code for android.content Context MEDIA_PROJECTION_SERVICE.
Click Source Link
From source file:Main.java
static void fireScreenCaptureIntent(Activity activity) { MediaProjectionManager manager = (MediaProjectionManager) activity .getSystemService(Context.MEDIA_PROJECTION_SERVICE); Intent intent = manager.createScreenCaptureIntent(); activity.startActivityForResult(intent, CREATE_SCREENSHOT); Log.i("TakeScreenshotService", "fireScreenCaptureIntent..."); }
From source file:com.orpheusdroid.screenrecorder.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* w ww. j av a2 s .c om*/ //Arbitrary "Write to external storage" permission since this permission is most important for the app requestPermissionStorage(); //final boolean isServiceRunning = isServiceRunning(RecorderService.class); //Let's add SettingsPreferenceFragment to the activity FragmentManager mFragmentManager = getFragmentManager(); FragmentTransaction mFragmentTransaction = mFragmentManager.beginTransaction(); SettingsPreferenceFragment mPrefsFragment = new SettingsPreferenceFragment(); mFragmentTransaction.replace(R.id.settingsFragment, mPrefsFragment); mFragmentTransaction.commit(); //Acquiring media projection service to start screen mirroring mProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); //Respond to app shortcut if (getIntent().getAction() != null && getIntent().getAction().equals(getString(R.string.app_shortcut_action))) { startActivityForResult(mProjectionManager.createScreenCaptureIntent(), SCREEN_RECORD_REQUEST_CODE); return; } fab = (FloatingActionButton) findViewById(R.id.fab); if (isServiceRunning(RecorderService.class)) { Log.d(Const.TAG, "service is running"); changeFabIcon(Status.RECORDING); } fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mMediaProjection == null && !isServiceRunning(RecorderService.class)) { //Request Screen recording permission startActivityForResult(mProjectionManager.createScreenCaptureIntent(), SCREEN_RECORD_REQUEST_CODE); } else if (isServiceRunning(RecorderService.class)) { //stop recording if the service is already active and recording Intent stopRecording = new Intent(MainActivity.this, RecorderService.class); stopRecording.setAction(Const.SCREEN_RECORDING_STOP); startService(stopRecording); changeFabIcon(Status.STOPPED); } } }); fab.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { //Show hint toast based on recording status if (isServiceRunning(RecorderService.class)) Toast.makeText(MainActivity.this, R.string.fab_record_hint, Toast.LENGTH_SHORT).show(); else Toast.makeText(MainActivity.this, R.string.fab_stop_hint, Toast.LENGTH_SHORT).show(); return true; } }); }
From source file:com.example.android.screencapture.ScreenCaptureFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Activity activity = getActivity();/* w w w . j ava 2 s . c o m*/ DisplayMetrics metrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); mScreenDensity = metrics.densityDpi; mMediaProjectionManager = (MediaProjectionManager) activity .getSystemService(Context.MEDIA_PROJECTION_SERVICE); }
From source file:com.orpheusdroid.screenrecorder.RecorderService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { //return super.onStartCommand(intent, flags, startId); //Find the action to perform from intent switch (intent.getAction()) { case Const.SCREEN_RECORDING_START: /* Wish MediaRecorder had a method isRecording() or similar. But, we are forced to * manage the state ourself. Let's hope the request is honored. * Request: https://code.google.com/p/android/issues/detail?id=800 */ if (!isRecording) { //Get values from Default SharedPreferences getValues();// w w w .j a va 2 s.c o m Intent data = intent.getParcelableExtra(Const.RECORDER_INTENT_DATA); int result = intent.getIntExtra(Const.RECORDER_INTENT_RESULT, Activity.RESULT_OK); //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(); isRecording = true; 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(createNotification(action).build(), Const.SCREEN_RECORDER_NOTIFICATION_ID); } else startNotificationForeGround(createNotification(null).build(), Const.SCREEN_RECORDER_NOTIFICATION_ID); } else { Toast.makeText(this, R.string.screenrecording_already_active_toast, Toast.LENGTH_SHORT).show(); } break; case Const.SCREEN_RECORDING_PAUSE: pauseScreenRecording(); break; case Const.SCREEN_RECORDING_RESUME: resumeScreenRecording(); break; case Const.SCREEN_RECORDING_STOP: stopScreenSharing(); //The service is started as foreground service and hence has to be stopped stopForeground(true); break; } return START_STICKY; }
From source file:com.flyingcrop.ScreenCaptureFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Activity activity = getActivity();//from w ww .ja v a 2 s. c o m mMediaProjectionManager = (MediaProjectionManager) activity .getSystemService(Context.MEDIA_PROJECTION_SERVICE); startScreenCapture(); }
From source file:com.yschi.castscreen.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (savedInstanceState != null) { mResultCode = savedInstanceState.getInt(STATE_RESULT_CODE); mResultData = savedInstanceState.getParcelable(STATE_RESULT_DATA); }/*from w w w .j ava 2 s .com*/ mContext = this; mMediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); mDiscoverdMap = new HashMap<>(); mDiscoverListView = (ListView) findViewById(R.id.discover_listview); mDiscoverAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1); mDiscoverAdapter.addAll(mDiscoverdMap.keySet()); mDiscoverListView.setAdapter(mDiscoverAdapter); mDiscoverListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { String name = mDiscoverAdapter.getItem(i); String ip = mDiscoverdMap.get(name); Log.d(TAG, "Select receiver name: " + name + ", ip: " + ip); mReceiverIp = ip; updateReceiverStatus(); mContext.getSharedPreferences(PREF_COMMON, 0).edit().putString(PREF_KEY_RECEIVER, mReceiverIp) .commit(); } }); // add server mode option mDiscoverAdapter.add(mContext.getString(R.string.server_mode)); mDiscoverdMap.put(mContext.getString(R.string.server_mode), ""); mReceiverTextView = (TextView) findViewById(R.id.receiver_textview); final EditText ipEditText = (EditText) findViewById(R.id.ip_edittext); final Button selectButton = (Button) findViewById(R.id.select_button); selectButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (ipEditText.getText().length() > 0) { mReceiverIp = ipEditText.getText().toString(); Log.d(TAG, "Using ip: " + mReceiverIp); updateReceiverStatus(); mContext.getSharedPreferences(PREF_COMMON, 0).edit() .putString(PREF_KEY_INPUT_RECEIVER, mReceiverIp).commit(); mContext.getSharedPreferences(PREF_COMMON, 0).edit().putString(PREF_KEY_RECEIVER, mReceiverIp) .commit(); } } }); ipEditText.setText(mContext.getSharedPreferences(PREF_COMMON, 0).getString(PREF_KEY_INPUT_RECEIVER, "")); Spinner formatSpinner = (Spinner) findViewById(R.id.format_spinner); ArrayAdapter<CharSequence> formatAdapter = ArrayAdapter.createFromResource(this, R.array.format_options, android.R.layout.simple_spinner_item); formatAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); formatSpinner.setAdapter(formatAdapter); formatSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mSelectedFormat = FORMAT_OPTIONS[i]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_FORMAT, i).commit(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { mSelectedFormat = FORMAT_OPTIONS[0]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_FORMAT, 0).commit(); } }); formatSpinner.setSelection(mContext.getSharedPreferences(PREF_COMMON, 0).getInt(PREF_KEY_FORMAT, 0)); Spinner resolutionSpinner = (Spinner) findViewById(R.id.resolution_spinner); ArrayAdapter<CharSequence> resolutionAdapter = ArrayAdapter.createFromResource(this, R.array.resolution_options, android.R.layout.simple_spinner_item); resolutionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); resolutionSpinner.setAdapter(resolutionAdapter); resolutionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mSelectedWidth = RESOLUTION_OPTIONS[i][0]; mSelectedHeight = RESOLUTION_OPTIONS[i][1]; mSelectedDpi = RESOLUTION_OPTIONS[i][2]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_RESOLUTION, i).commit(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { mSelectedWidth = RESOLUTION_OPTIONS[0][0]; mSelectedHeight = RESOLUTION_OPTIONS[0][1]; mSelectedDpi = RESOLUTION_OPTIONS[0][2]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_RESOLUTION, 0).commit(); } }); resolutionSpinner .setSelection(mContext.getSharedPreferences(PREF_COMMON, 0).getInt(PREF_KEY_RESOLUTION, 0)); Spinner bitrateSpinner = (Spinner) findViewById(R.id.bitrate_spinner); ArrayAdapter<CharSequence> bitrateAdapter = ArrayAdapter.createFromResource(this, R.array.bitrate_options, android.R.layout.simple_spinner_item); bitrateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); bitrateSpinner.setAdapter(bitrateAdapter); bitrateSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { mSelectedBitrate = BITRATE_OPTIONS[i]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_BITRATE, i).commit(); } @Override public void onNothingSelected(AdapterView<?> adapterView) { mSelectedBitrate = BITRATE_OPTIONS[0]; mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_BITRATE, 0).commit(); } }); bitrateSpinner.setSelection(mContext.getSharedPreferences(PREF_COMMON, 0).getInt(PREF_KEY_BITRATE, 0)); mReceiverIp = mContext.getSharedPreferences(PREF_COMMON, 0).getString(PREF_KEY_RECEIVER, ""); updateReceiverStatus(); startService(); }
From source file:com.att.arocollector.AROCollectorActivity.java
@TargetApi(21) private void getVideoCapturePermission() { mediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE); startActivityForResult(mediaProjectionManager.createScreenCaptureIntent(), Config.Permission.VIDEO_PERMISSION_REQUEST_CODE); }