简体   繁体   中英

How to share images to Gmail from internal memory?

In the following i was succesful in saving screenshot in internal memory. But Gmail and many other apps say they cant share an empty file except whatsapp and bluetooth. I know internal memory does not allow sharing between apps. I used Environment.getExternalDirectory. My aim is to available it to Gmail. I have read all the previous questions and I couldnt find the solution with this. How do I share and whats the mistake? What i'm missing here? The getExternalStorageDirectory() gives path to sdcard0 which is in case my internal memory here and my sdcard is 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();
}

Well try This Code To Share Screenshot To gmail or so

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"));

pass the bitmap in the insert.image()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM