开发者

problem in taking screenshots in android by programmatically

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:

开发者_Python百科
            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.


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();
            }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜