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!