0

I'm developing a screen recorder app that includes a floating widget. When users press on it, it calls the below code

MediaProjectionManager mediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);
        Intent permissionIntent = mediaProjectionManager != null ? mediaProjectionManager.createScreenCaptureIntent() : null;
        startActivityForResult(permissionIntent, 101);

after which I start the recording in on activity result method

if (requestCode == 101) {
            if (resultCode == RESULT_OK) {
                recorder.startScreenRecording(data, resultCode, this);
            }
        }

and everything works fine but when users press the floating widget when he is outside the app it doesn't pop up the permission dialog to start the recording, it only shows's the permission dialog when the user is in the app.

Any idea or suggestion please ... please...

anything please

Tehleel Mir
  • 743
  • 8
  • 27
  • 1
    https://developer.android.com/guide/components/activities/background-starts – CommonsWare Apr 10 '21 at 11:52
  • I have no idea how ur comment was useful @CommonsWare – Tehleel Mir Apr 10 '21 at 12:06
  • That document outlines that generally you cannot start activities from the background, such as from your floating window, on newer versions of Android. It outlines alternatives (such as a `Notification`) and what situations do allow you to start an activity from the background. – CommonsWare Apr 10 '21 at 12:08
  • will this answer help me in any way? https://stackoverflow.com/a/47082585/14599955 – Tehleel Mir Apr 10 '21 at 12:17
  • I do not know. That question, and its answers, are a few years old. They do not take into account the background-activity-start changes. However, I also do not know if the background-activity-start changes are at the root of your current problem. We do not know how your "floating widget" is implemented. Long term, those sorts of things will need to use the "bubbles" approach offered on Android 11+, as Google continues to tighten security around older approaches (e.g., those involving `SYSTEM_ALERT_WINDOW`). – CommonsWare Apr 10 '21 at 12:24
  • well I implement it and it does work perfectly, Thank you for your time @CommonsWare have a good day – Tehleel Mir Apr 10 '21 at 12:28

0 Answers0