I know this question has been asked quite often, but this seems to be different. I’ve tried 6 solutions from StackOverflow and it didn’t work. I’m trying to put the drawing someone made into a Notification.BigPictureStyle when they leave the app.
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
_thread.setRunning(true);
_thread.start();
setDrawingCacheEnabled(true);
}
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
_thread.setRunning(false);
measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
buildDrawingCache(false);
Bitmap currentState = Bitmap.createBitmap(getDrawingCache());
setDrawingCacheEnabled(false);
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(DrawActivity.this, DrawActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(DrawActivity.this, 0, notificationIntent, Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
Notification noti = new Notification.BigPictureStyle(
new Notification.Builder(DrawActivity.this)
.setContentTitle("Your drawing")
.setContentText("Unfold to see drawing")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_launcher)
.setContentIntent(contentIntent))
.setSummaryText("Here you can see how you left your drawing.")
.bigPicture(currentState)
.build();
manager.notify(1023, noti);
}
}
But I always get a NullPointerException at this line:
Bitmap currentState = Bitmap.createBitmap(getDrawingCache());
This code is from StackOverflow with enabling all these caches. Can someone see what’s wrong?
By the way, I’m using Android 4.1.1 of course.
Similar question here more info here…
Problem appears to be that you can’t access contents of a surfaceview – apparently you can capture the contents of an ImageView… I assume your using a surfaceView and thus encountering the same problem… If your willing to dig further this might help (from one of the above threads/topics)
If your not using a surfaceview then setLayerType might be your answer…