问题
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