javaandroidandroid-serviceandroid-notificationsandroid-mediaprojection

Recording screen from notification instead of MainActivity and using multiple notifications for each recording?


Not sure if this is the right place since this question might be flagged as opinion-based however what I need is mainly advice on the architecture.

I have developed an app that record the screen (using the media projection API) and perform some analysis (foreground service) on the output video. So far I am basically starting the request of screen capture in the main activity and then starting a service. MainActivity:

 @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (requestCode==REQUEST_SCREENCAST) {
                if (resultCode==RESULT_OK) {
                   startService(resultCode, data);
                }
            }
            finish();
        }
    
    
        button.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                        startActivityForResult(mediaProjectionManager.createScreenCaptureIntent(), REQUEST_SCREENCAST);
                }
            });
    

Service:

     public int onStartCommand(Intent intent, int flags, int startId) {
            int resultCode = intent.getIntExtra(EXTRA_RESULT_CODE, 1337);
            Intent data = intent.getParcelableExtra(EXTRA_RESULT_INTENT);
            //...
            mediaProjection = mediaProjectionManager.getMediaProjection(resultCode, data);
            //...
            return super.onStartCommand(Intent intent, int flags, int startId);
            }

In the service I set up the mediaprojection, start and stop the recording and finally start the process that analyze the output video. I keep track of the progress in the notification bar.

I would like your suggestion on:

Thank you.


Solution

  • Would be more appropriate to start the recording directly from a button in the notification bar?

    That depends on whether or not you already obtained permission. A Notification cannot readily use startActivityForResult(). As a result, mediaProjectionManager.createScreenCaptureIntent() will need to be used from the activity. If you did that previously, and are simply looking to use the Notification to trigger recording, that might work.

    Would be more appropriate to give the user the opportunity to start other recordings while the analysis on previous recordings is being done?

    The device might not have enough capability to do both things at once.

    should I use the main activity to keep track of all processes or should I use multiple notifications?

    I would avoid multiple notifications.