/// <summary>
        /// 初始化截屏服务。
        /// </summary>
        /// <param name="data"></param>
        /// <param name="context"></param>
        /// <param name="handler"></param>
        public void Init(Intent data, Context context)
        {
            if (IsInit)
            {
                return;
            }

            volatileDispose           = new VolatileDispose();
            _intent                   = data;
            Context                   = context;
            _mediaProjectionManager   = AppApplication.GetSystemService <MediaProjectionManager>(Context.MediaProjectionService);
            _orientationEventListener = new OrientationEvent(context, i =>
            {
                try
                {
                    RefreshVirtualDisplay();
                }
                catch (Exception)
                {
                }
            });

            if (_orientationEventListener.CanDetectOrientation())
            {
                _orientationEventListener.Enable();
            }

            IsInit = true;
        }
        public bool Start(Intent MediaProjectionToken = null)
        {
            if (ServiceStarted)
            {
                return(false);
            }

            if (MediaProjectionToken != null)
            {
                _mediaProjection = MediaProjectionManager.GetMediaProjection((int)Result.Ok, MediaProjectionToken);
            }

            _imageReader = ImageReader.NewInstance(_screenWidth, _screenHeight, (ImageFormatType)1, 2);
            _imgListener = new ImgListener(_imageReader);
            _imageReader.SetOnImageAvailableListener(_imgListener, null);

            SetupVirtualDisplay();

            _windowManager.AddView(_layout, _layoutParams);
            ServiceStarted = true;

            ShowForegroundNotification();

            return(true);
        }
        /**
         * on create bundle
         */
        protected override void OnCreate(Bundle savedInstanceState)
        {
            try
            {
                _context = this;

                TabLayoutResource = Resource.Layout.Tabbar;
                ToolbarResource   = Resource.Layout.Toolbar;

                Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);

                base.OnCreate(savedInstanceState);
                global::Xamarin.Forms.Forms.SetFlags("IndicatorView_Experimental");
                global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

                MediaProjectionManager manager = GetSystemService(MediaProjectionService).JavaCast <MediaProjectionManager>();
                Intent screenCaptureIntent     = manager.CreateScreenCaptureIntent();

                //Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, savedInstanceState);
                Forms9Patch.Droid.Settings.Initialize(this);

                LoadApplication(new App(screenCaptureIntent));

                this.Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);
                Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            }
            catch {
            }
        }
Exemple #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            var metrics = new DisplayMetrics();

            MessagingCenter.Subscribe <string, string>("OnButtonClicked", "ButtonClickEvent", (sender, arg) =>
            {
                StopRecording(true);
            });
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            mediaProjectionManager = (MediaProjectionManager)this.GetSystemService(Context.MediaProjectionService);
            mMediaRecorder         = new MediaRecorder();
            StartActivityForResult(mediaProjectionManager.CreateScreenCaptureIntent(),
                                   REQUEST_SCREENCAST);
            if (savedInstanceState != null)
            {
                ResultCode = savedInstanceState.GetInt(STATE_RESULT_CODE);
                ResultData = (Intent)savedInstanceState.GetParcelable(STATE_RESULT_DATA);
            }
            metrics = new DisplayMetrics();
            LoadApplication(new App());
        }
Exemple #5
0
        bool RegisterScreenshot(Intent MediaProjectionToken)
        {
            IScreenshotService sshotService;

            try
            {
                if (MediaProjectionToken != null)
                {
                    var mediaProjection = MediaProjectionManager.GetMediaProjection((int) Result.Ok, MediaProjectionToken);
                    sshotService = new MediaProjectionScreenshotService(mediaProjection, _metrics);
                }
                else
                {
                    sshotService = new RootScreenshotService(GetSuperUser());
                }
            }
            catch (Exception e)
            {
                Toast.MakeText(this, e.Message, ToastLength.Short).Show();
                return false;
            }

            _sshotService = sshotService;
            ScreenshotManager.Register(_sshotService);
            return true;
        }
		public override void OnActivityCreated (Bundle savedInstanceState)
		{
			base.OnActivityCreated (savedInstanceState);
			var metrics = new DisplayMetrics ();
			Activity.WindowManager.DefaultDisplay.GetMetrics (metrics);
			screenDensity = (int)metrics.DensityDpi;
			mediaProjectionManager = (MediaProjectionManager)Activity.GetSystemService (Context.MediaProjectionService);
		}
        public override void OnActivityCreated(Bundle savedInstanceState)
        {
            base.OnActivityCreated(savedInstanceState);
            var metrics = new DisplayMetrics();

            Activity.WindowManager.DefaultDisplay.GetMetrics(metrics);
            screenDensity          = (int)metrics.DensityDpi;
            mediaProjectionManager = (MediaProjectionManager)Activity.GetSystemService(Context.MediaProjectionService);
        }
Exemple #8
0
        /// <summary>
        /// 初始化截屏服务。
        /// </summary>
        /// <param name="data"></param>
        /// <param name="context"></param>
        public void Init(Intent data)
        {
            if (_isInit)
            {
                return;
            }

            _intent  = data;
            _handler = new Handler();
            _mediaProjectionManager = AppUtils.GetSystemService <MediaProjectionManager>(Context.MediaProjectionService);
            _isInit = true;
        }
        //readonly DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

        //long CurrentTimeMillis()
        //{
        //    return (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
        //}


        public ScreenRecorder()
        {
            mainActivity = (Forms.Context as Activity);
            //服务第一次创建进行初始化
            mediaProjectionManager = (MediaProjectionManager)Forms.Context.GetSystemService(Context.MediaProjectionService);
            mediaRecorder          = new MediaRecorder();

            DisplayMetrics metrics = new DisplayMetrics();

            mainActivity.WindowManager.DefaultDisplay.GetMetrics(metrics);
            screenDensity = metrics.DensityDpi;
        }
 /**
  * verificacion del soporte de icelink android
  */
 protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
 {
     if (requestCode == 42 && FM.IceLink.Android.Utility.IsSDKVersionSupported(BuildVersionCodes.Lollipop))
     {
         if (data == null)
         {
             Alert("Must allow screen sharing before the chat can start.");
         }
         else
         {
             MediaProjectionManager manager = GetSystemService(MediaProjectionService).JavaCast <MediaProjectionManager>();
             Multimedia.Context.Instance.MediaProjection = manager.GetMediaProjection((int)resultCode, data);
             IsMediaProjection = true;
         }
     }
 }
Exemple #11
0
        public void Init()
        {
            if (Build.VERSION.SdkInt < BuildVersionCodes.Q) // broadcast is only supported on Android 10 and up
            {
                return;
            }

            NotificationManager notificationManager =
                (NotificationManager)Application.Context.GetSystemService(Application.NotificationService);
            NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
                                                                  "Snapclient service", NotificationImportance.Low);

            channel.Description = "Snapcast broadcast service";
            notificationManager.CreateNotificationChannel(channel);

            m_MediaProjectionManager = (MediaProjectionManager)Application.Context.GetSystemService(MediaProjectionService);
        }
Exemple #12
0
        public void StartRecording(Bundle savedInstanceState)
        {
            string path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/test.mp4";

            mMediaRecorder.SetVideoSource(VideoSource.Surface);
            mMediaRecorder.SetOutputFormat(OutputFormat.Webm);
            //mMediaRecorder.SetVideoEncodingBitRate(512 * 1000);
            mMediaRecorder.SetVideoEncoder(VideoEncoder.Vp8);
            mMediaRecorder.SetVideoSize(480, 640);
            //mMediaRecorder.SetVideoFrameRate(10);
            mMediaRecorder.SetOutputFile(path);
            mMediaRecorder.Prepare();

            var metrics = new DisplayMetrics();

            Activity.WindowManager.DefaultDisplay.GetMetrics(metrics);
            screenDensity          = (int)metrics.DensityDpi;
            mediaProjectionManager = (MediaProjectionManager)Activity.GetSystemService(Context.MediaProjectionService);

            resultCode      = savedInstanceState.GetInt(STATE_RESULT_CODE);
            resultData      = (Intent)savedInstanceState.GetParcelable(STATE_RESULT_DATA);
            mediaProjection = mediaProjectionManager.GetMediaProjection(resultCode, resultData);
            mMediaRecorder.Start();
        }
Exemple #13
0
 private void _StartMediaProjectionRequest()
 {
     m_MediaProjectionmanager = Android.App.Application.Context.GetSystemService(Context.MediaProjectionService) as MediaProjectionManager;
     StartActivityForResult(m_MediaProjectionmanager.CreateScreenCaptureIntent(), MEDIA_PROJECTION_REQUEST_CODE);
 }