1

この質問はよく聞かれますが、これは違うようです。StackOverflow から 6 つのソリューションを試しましたが、うまくいきませんでした。Notification.BigPictureStyleアプリを離れるときに誰かが描いた絵を入れようとしています。

    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);

    }
}

しかし、私はいつもNullPointerExceptionこの行に

Bitmap currentState = Bitmap.createBitmap(getDrawingCache());

このコードは、これらすべてのキャッシュを有効にした StackOverflow からのものです。誰かが何が悪いのか見ることができますか?

ちなみに、もちろんAndroid 4.1.1を使っています。

4

1 に答える 1

0

ここに同様の質問詳細はこちら...

問題は、surfaceviewのコンテンツにアクセスできないことであるように見えます-どうやらImageViewのコンテンツをキャプチャできるようです... surfaceViewを使用しているため、同じ問題が発生していると思います...さらに掘り下げてみるとヘルプ(上記のスレッド/トピックの1つから)

サーフェスビューを使用していない場合は、setLayerTypeが答えかもしれません...

于 2012-08-27T22:01:12.317 に答える