Created
April 5, 2012 11:55
-
-
Save nikreiman/2310318 to your computer and use it in GitHub Desktop.
Take a screenshot of your Android app and email it somewhere (no root access required)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void sendFeedbackScreenshot(final Activity activity) { | |
try { | |
final View rootView = activity.getWindow().getDecorView().findViewById(android.R.id.content); | |
rootView.setDrawingCacheEnabled(true); | |
Bitmap bitmap = rootView.getDrawingCache(); | |
// Activity.getCacheDir() won't work here, because the email intent can't | |
// access your app's internal storage. So you need to find a good temporary | |
// location in SD card storage. | |
File outputDir = new File(android.os.Environment.getExternalStorageDirectory(), "tmp"); | |
File outputFile = new File(outputDir, "screenshot.png"); | |
FileOutputStream fileOutputStream; | |
fileOutputStream = new FileOutputStream(outputFile); | |
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream); | |
rootView.setDrawingCacheEnabled(false); | |
startEmailActivity(activity, Uri.fromFile(outputFile)); | |
} | |
catch(Exception e) { | |
// Show error message, etc. | |
} | |
} | |
public static void startEmailActivity(Context context, Uri attachment) { | |
Intent sendEmailIntent = new Intent(Intent.ACTION_SEND); | |
sendEmailIntent.setType("message/rfc822"); | |
sendEmailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{TO_EMAIL_ADDRESS}); | |
sendEmailIntent.putExtra(Intent.EXTRA_SUBJECT, YOUR_EMAIL_SUBJECT); | |
sendEmailIntent.putExtra(Intent.EXTRA_STREAM, attachment); | |
context.startActivity(Intent.createChooser(sendEmailIntent, "Send email")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sir, Thanks for posting this code. Can you share the complete android project code?