1

你好 stackoverflow 社区,

我搜索了很多关于将照片附加到电子邮件的信息。我找到了有效的代码,但图片的分辨率很差。现在我想发送未压缩的图片。于是我看了很多问题,找到了这段代码,但是拍照的时候接受不了,继续往下看。

在这里您可以查看我的代码:

this.eco.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            Intent cameraIntent = new Intent(
                    android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            File path = new File("/Pictures/");
            path.mkdirs();
            String fileName = "verunreinigung.jpg";
            File file = new File(path, fileName);
            cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,
                    Uri.fromFile(file));
            startActivityForResult(cameraIntent, CAMERA_REQUEST_CODE);
        }
    });

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    if (requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");

        // variables
        int latitude = GMapsSubActivity.getLatitude();
        int longitude = GMapsSubActivity.getLongitude();
        double dLat = latitude / 1000000.0;
        double dLng = longitude / 1000000.0;

        Log.v("lat", Integer.toString(latitude));
        Log.v("lng", Integer.toString(longitude));
        Log.v("lat", Double.toString(dLat));
        Log.v("lng", Double.toString(dLng));

        String[] address = new String[]{cursor.getString(cursor.getColumnIndex("email"))};
        String subject = "Verunreinigung am Gewässer: " + cursor.getString(cursor.getColumnIndex("gewName"))
                + " / " + cursor.getString(cursor.getColumnIndex("reviergrenzen"));
        String text = "Hallo " + cursor.getString(cursor.getColumnIndex("name"))
                + "!\n\nIch habe an/in Ihrem Gewässer eine"
                + " Verunreinigung entdeckt.\n"
                + "Sie befindet sich hier:\n"
                + "http://maps.google.com/?q=" + dLat + "," + dLng + "\n"
                + "Das Foto finden Sie im Anhang.\n\nLiebe Grüße!";

        ContentValues values = new ContentValues();
        values.put(Images.Media.TITLE, "photo");
        values.put(Images.Media.BUCKET_ID, "photo_ID");
        values.put(Images.Media.DESCRIPTION, "");
        values.put(Images.Media.MIME_TYPE, "image/jpeg");

        Uri photoUri = getContentResolver().insert(
                Media.EXTERNAL_CONTENT_URI, values);
        OutputStream outstream;

        try {
            outstream = getContentResolver().openOutputStream(photoUri);
            photo.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
            outstream.close();
        } catch (FileNotFoundException e) {

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // define the intent
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, address);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, text);
        emailIntent.putExtra(Intent.EXTRA_STREAM, photoUri);

        emailIntent.setType("plain/text");

        // start the intent
        try {
            startActivity(Intent.createChooser(emailIntent,
                    "Versende Email via:"));
        } catch (android.content.ActivityNotFoundException ex) {
            Toast.makeText(getApplicationContext(),
                    "Kein Email-Programm installiert.", Toast.LENGTH_SHORT)
                    .show();
        }
    }  
}
4

1 回答 1

0

使用以下代码发送邮件

String filelocation="/mnt/sdcard/capture.png";    
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("vnd.android.cursor.dir/email");
String to[] = "user@gmail.com";
sharingIntent.putExtra(Intent.EXTRA_EMAIL, to);
sharingIntent.putExtra(Intent.EXTRA_STREAM,filelocation);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,"subject");
startActivity(Intent.createChooser(sharingIntent, "Send email"));
于 2013-01-10T13:36:58.260 回答