Take realtime screenshot while video calling android

匆匆过客 提交于 2019-12-24 06:24:06

问题


I have problem with my android code for taking screenshot while on video calling

I found several method for take screenshot on specific layout and this is what I used :

private void takeScreenshot() {
    final FrameLayout container = (FrameLayout) findViewById(R.id.remote_video_view_container);
    Date now = new Date();
    android.text.format.DateFormat.format("yyyy-MM-dd_hh:mm:ss", now);

    try {
        // image naming and path  to include sd card  appending name you choose for file
        String mPath = Environment.getExternalStorageDirectory().toString() + "/" + now + ".jpg";

        // create bitmap screen capture
        container.setDrawingCacheEnabled(true);
        Bitmap bitmap = Bitmap.createBitmap(container.getDrawingCache());
        container.setDrawingCacheEnabled(false);

        File imageFile = new File(mPath);

        FileOutputStream outputStream = new FileOutputStream(imageFile);
        int quality = 100;
        bitmap.compress(Bitmap.CompressFormat.JPEG, quality, outputStream);

        if(mPath!=null){
            Toast savedToast = Toast.makeText(getApplicationContext(),
                    "Drawing saved to Gallery!", Toast.LENGTH_SHORT);
            savedToast.show();
        }
        else{
            Toast unsavedToast = Toast.makeText(getApplicationContext(),
                    "Oops! Image could not be saved.", Toast.LENGTH_SHORT);
            unsavedToast.show();
        }
        outputStream.flush();
        outputStream.close();

        openScreenshot(imageFile);
    } catch (Throwable e) {
        // Several error may come out with file handling or DOM
        e.printStackTrace();
    }
}

private void openScreenshot(File imageFile) {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    Uri uri = Uri.fromFile(imageFile);
    intent.setDataAndType(uri, "image/*");
    startActivity(intent);
}

i try this code for save my draw painting application that will save the drawing layout and then i try to use the same method for save video call layout but return black screen image. i found that this method cannot use for real-time when i want to record it in video

source : How to programmatically take a screenshot in Android?

so, anyone help me what the best way to solve my problem ?

来源:https://stackoverflow.com/questions/47405244/take-realtime-screenshot-while-video-calling-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!