problem in taking screenshots in android by programmatically

本秂侑毒 提交于 2021-02-08 11:55:25

问题


in my app i am taking screenshot of the current screen and save it in sdcard. but in the case screenshot is not saved in sdcard. how to take screen shot and send the captured screen shot in email as attachment. please help me.

my coding:

            View v1 = view.getRootView();
            v1.setDrawingCacheEnabled(true);
            Bitmap bm = v1.getDrawingCache();
            try 
            {
                   System.out.println("path "+Environment.getExternalStorageDirectory());
                   FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory()+"/ff");
                   bm.compress(CompressFormat.PNG, 90, out);
            }
            catch (Exception e) 
            {
                   e.printStackTrace();
            }

            Intent emailIntent = new Intent(Intent.ACTION_SEND); 
            Uri U=Uri.parse("file:///sdcard/ff");
            emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { "aabc@gmail.com" });
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, " from ..");
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "from the app");
            emailIntent.setType("image/png");
//          emailIntent.putExtra(android.content.Intent.EXTRA_STREAM,U);
            emailIntent.putExtra(Intent.EXTRA_STREAM, U);
            startActivity(Intent.createChooser(emailIntent, "")); 

please help me.


回答1:


i solved my problem by replace the try clause coding by

            File file = new File(Environment.getExternalStorageDirectory()+"/filmfestival.png");
            try 
            {
                file.createNewFile();
                FileOutputStream ostream = new FileOutputStream(file);
                bitmap.compress(CompressFormat.PNG, 100, ostream);
                ostream.close();
            } 
            catch (Exception e) 
            {
                e.printStackTrace();
            }


来源:https://stackoverflow.com/questions/7552619/problem-in-taking-screenshots-in-android-by-programmatically

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