这是我的代码。它共享相同的旧屏幕截图,如何删除旧屏幕截图并生成新屏幕截图。而且,在Facebook上分享时,它不会添加我提供的链接。它只在facebook上的whatsapp上分享了它的工作正常截图,但却分享了相同的旧图片。
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();
}
答案 0 :(得分:0)
我得到了解决方案,我必须使用绘图缓存。使用view.invalidate() befre setDrawingCacheEnabled(true)。
public Bitmap takeScreenshot() {
View rootView = findViewById(android.R.id.content).getRootView();
rootView.invalidate();
rootView.setDrawingCacheEnabled(true);
return rootView.getDrawingCache();
}