在下文中,我成功地在内存中保存了屏幕截图。但Gmail和许多其他应用程序表示,除了whatsapp和蓝牙之外,他们无法共享一个空文件。我知道内部存储器不允许在应用程序之间共享。我使用了Environment.getExternalDirectory。 我的目标是将其提供给Gmail。 我已经阅读了所有以前的问题,但我找不到解决方案。 我该如何分享并解决这个错误?我在这里失踪了什么? getExternalStorageDirectory()给出sdcard0的路径,以防万一我的内存和我的sdcard是sdcard1。
public void captureScreen()
{
GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback()
{
@Override
public void onSnapshotReady(Bitmap snapshot)
{
try
{
FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/MapScreenshot"+System.currentTimeMillis()+".png");
snapshot.compress(Bitmap.CompressFormat.PNG, 90, out);
Toast.makeText(Map.this, "Path Captured as Image, saved in" + path,Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
Log.e("Image not saved", "");
e.printStackTrace();
}
}
};
googleMap.snapshot(callback);
AlertDialog.Builder builder=new AlertDialog.Builder(this);
builder.setMessage(R.string.dialog_share_text).setPositiveButton(R.string.share_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//user shared
Intent sharingIntent=new Intent(Intent.ACTION_SEND);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(path));
startActivity(Intent.createChooser(sharingIntent, "Share Image Using"));
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//user cancelled
}
}).show();
}
答案 0 :(得分:0)
请尝试使用此代码共享Screenshot
至gmail
左右
String path = Images.Media.insertImage(getContentResolver(), yourBitmap,
"title", null);
Uri screenshotUri = Uri.parse(path);
final Intent emailIntent1 = new Intent(
android.content.Intent.ACTION_SEND);
emailIntent1.setType("text/plain");
emailIntent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
emailIntent1.putExtra(Intent.EXTRA_STREAM, screenshotUri);
emailIntent1.setType("image/png");
startActivity(Intent
.createChooser(emailIntent1, "Send email using"));
传递insert.image()