1
這是我的代碼。它共享相同的舊屏幕截圖,我如何刪除舊的屏幕截圖並生成一個新的屏幕截圖。而且在Facebook上分享時,它不會添加我提供的鏈接。它僅在whatsapp上的Facebook上共享屏幕截圖,但它共享相同的舊圖片。生成新的屏幕截圖
public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}
public void saveBitmap(Bitmap bitmap) {
imagePath = new File(Environment.getExternalStorageDirectory() + "/screenshot.png");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}}
private void shareIt() {
Uri uri = Uri.fromFile(imagePath);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("image/*");
String shareBody = "Can you solve this , I am stuck/n try your answer at www.shackless.shan.com";
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sharingIntent, "Challenge via"));
}
public void shareOnWhatsapp(View view) {
Bitmap bitmap = takeScreenshot();
saveBitmap(bitmap);
shareIt();
}