0

First, I believe this is the same issue as described by this SO post. I want to provide more details and be as specific as possible in the hope that some guru will come up with an elegant solution. This happens with Android 5.1

The following code

startActivityForResult(myMediaProjectionManager.createScreenCaptureIntent(), REQUEST_CODE_SCREEN_RECORDING);

will show the following prompt to the user:

enter image description here

If the user does not select "Don't show again", everything will work exactly as expected. Unfortunately, if "Don't show again" is selected, the same code will lead to the following prompt from the next run: enter image description here

The device will go to the lock screen after the prompt.

Could anyone confirm this is caused by a system bug and offer a remedy without asking the user to avoid selecting "Don't show again"?

Community
  • 1
  • 1
Hong
  • 17,643
  • 21
  • 81
  • 142

1 Answers1

1

Could anyone confirm this is caused by a system bug

If you are seeing the same Java stack trace as is reported in this issue, then yes, this would appear to have been a system bug.

and offer a remedy without asking the user to avoid selecting "Don't show again"?

Ask the user to upgrade their device. Apparently, this was fixed in 5.1.1.

Or, do not use MediaProjectionManager. The problem is not in your app, and so there is nothing that you can do to change the behavior.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks a lot for the prompt answer. Yes, I see exactly the same NPE exception in logcat. Is there comparable or even better alternative to using MediaProjectionManager for screen recording? – Hong Jul 07 '16 at 16:31
  • 1
    @Hong: No, sorry. Outside of rooted devices, `MediaProjectionManager` is your only option. – CommonsWare Jul 07 '16 at 16:35
  • Thanks for the clarification. MayI ask one more favor: how can I tell 5.1 from 5.1.1 in code? They are the same API level. Should I post another question for this? I did a quick search, but could not find an answer. – Hong Jul 07 '16 at 16:41
  • 1
    @Hong: I am not sure what the best approach would be for that. Looking at `Build.VERSION.RELEASE` and seeing if it starts with `5.1.1` *might* work, but I don't know if there is a better solution. – CommonsWare Jul 07 '16 at 16:49
  • Many thanks. This will do it. I have just tested Build.VERSION.RELEASE on a 5.1 and a 5.1.1 device and it is exactly 5.1 and 5.1.1 respectively. – Hong Jul 07 '16 at 16:59
  • 1
    @Hong: I worry that `RELEASE` may be more subject to manufacturer tinkering than are the API levels, so I would still use `startsWith()` instead of `equals()`. – CommonsWare Jul 07 '16 at 17:00
  • Thank you for the tip. I will try to check API 22, then contains(5.1) and not contains(5.1.1) to catch the real 5.1 that deserves special warning. – Hong Jul 07 '16 at 17:22