1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
private void start_Share( String fileName) {
File file = new File(this.getFilesDir(), fileName);
boolean deleted = file.delete();
maTable.setDrawingCacheEnabled(true); // maTable = nom du layout que je veux capturer (pas simplement une capture d'écran)
Bitmap mycatpure = maTable.getDrawingCache();
File myfile = store(mycatpure,fileName);
shareImage(myfile);
}
public File store(Bitmap bm, String fileName){
File file = new File(this.getFilesDir(), fileName);
try {
FileOutputStream fOut = openFileOutput(fileName, Context.MODE_WORLD_READABLE);
bm.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
} catch (Exception e) {
e.printStackTrace();
}
return file;
}
private void shareImage(File file){
Uri uri = Uri.fromFile(file);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.setType("image/jpeg");
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "");
intent.putExtra(android.content.Intent.EXTRA_TEXT, "");
intent.putExtra(Intent.EXTRA_STREAM, uri);
try {
startActivity(Intent.createChooser(intent, "Share Screenshot"));
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No App Available", Toast.LENGTH_SHORT).show();
}
} |
Partager