【发布时间】:2017-04-27 12:36:02
【问题描述】:
我有应用程序,我让用户制作屏幕截图并分享它,一切正常,只是一个问题..
例如当用户截屏并按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() ,
"SCREEN"
+ System.currentTimeMillis() + ".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.fromFile(imagePath);
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("image/*");
String shareBody = "جرب تطبيق نكت عراقية مضحكة الان!";
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "تطبيق نكت
عراقية مضحكة");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(sharingIntent, "مشاركة بواسطة"));
}
【问题讨论】:
-
你好,我只是想问你关于截图部分,这段代码是截取你设备的布局还是主屏幕?
-
这个问题只发生在 facebook 上吗?
-
截取新的截图就删掉就好了。
-
@Mousa,所有的布局,取决于你把它放在哪里,(活动的意思)
-
@layth ,嗯...,谢谢,但我正在尝试对设备的主屏幕进行屏幕截图。
标签: java android share screenshot