2

I am currently using Android 5.0 MediaProjection API. I have successfully been able to start a projection session from my application, however I have noticed that the user can at any point in time go to the notification bar and stop media projection. My goal is to capture this event and do some cleanup actions. I have registered a MediaProjection.Callback in my MediaProjection object, however, when I manually cancel projection from the notification bar and the system tries to call onStop method of my MediaProjection.Callback I receive a nullpointer exception as follows:

03-24 12:54:56.575: W/Binder(9589): Caught a RuntimeException from the binder stub implementation.
03-24 12:54:56.575: W/Binder(9589): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.projection.MediaProjection$CallbackRecord.onStop()' on a null object reference
03-24 12:54:56.575: W/Binder(9589):     at android.media.projection.MediaProjection$MediaProjectionCallback.onStop(MediaProjection.java:188)
03-24 12:54:56.575: W/Binder(9589):     at android.media.projection.IMediaProjectionCallback$Stub.onTransact(IMediaProjectionCallback.java:49)
03-24 12:54:56.575: W/Binder(9589):     at android.os.Binder.execTransact(Binder.java:446)

My MediaProjection.Callback at this point virtually does nothing, I am pasting it for completeness:

private class MediaProjectionCallback extends MediaProjection.Callback {
    @Override
    public void onStop() {
        Log.e("MediaProjection", "onStop");
    }
}

Any ideas why this is occurring?

Many thanks in advance!

fadden
  • 51,356
  • 5
  • 116
  • 166
mtsahakis
  • 793
  • 1
  • 8
  • 18
  • Looks like a possible bug: https://code.google.com/p/android/issues/detail?id=148937 You aren't the one calling a method on a `null` object; the framework is. – CommonsWare Mar 24 '15 at 13:22
  • Yeah looks like it. Is there any other callback API that registers user cancelling projection event? – mtsahakis Mar 24 '15 at 15:06
  • I haven't used the `MediaProjection` API yet, so I don't know -- sorry! – CommonsWare Mar 24 '15 at 15:07
  • A bug is filed on the issue https://code.google.com/p/android/issues/detail?id=148937. A workaround is welcome though :) – mtsahakis Mar 24 '15 at 23:09

1 Answers1

2

This was apparently fixed in Android 5.1 release.

mtsahakis
  • 793
  • 1
  • 8
  • 18