Şu anda resim çekecek ve o resmi önceden belirlenmiş bir e-posta adresine gidecek bir e-postaya ekleyecek bir uygulama oluşturmaya çalışıyorum.Android: Bir resmi e-posta eki olarak nasıl gönderirim?
E-posta çalışıyor ve kameranın çalışmasını sağlarım. Fotoğraf makinesinin ek olarak eklemek için çektiği resmi elde edemiyorum. Uygulamamda bir görüntü önyükleme görüntüsü olarak çıkıyorum, bu yüzden takılmayacaksa neden sorun değil.
E-posta gönderildiğinde, bir resim oluşturuldu ancak bozuk ve açılmıyor. Var olmayan bir resim oluşturuyormuşum gibi. Sanırım ek oluşturma kısmına çekilen resmi bağlama olayı olacağını düşünüyorum ama hiçbir fikrim yok! Herhangi biri yardım ederse son derece minnettar olurdum!
İşte benim e-posta kamera ile birlikte oluşturulmaktadır MainActivity
:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Images.Media;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class EmailActivity extends Activity {
Button send;
EditText address, subject, emailtext;
protected static final int CAMERA_PIC_REQUEST = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.email);
send=(Button) findViewById(R.id.emailsendbutton);
address=(EditText) findViewById(R.id.emailaddress);
subject=(EditText) findViewById(R.id.emailsubject);
emailtext=(EditText) findViewById(R.id.emailtext);
send.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if
(!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
{
}
File pngDir = new File(
Environment.getExternalStorageDirectory(),
"Android/data/com.phstudios.jbrefurb/quote");
if (!pngDir.exists())
pngDir.mkdirs();
File pngFile = new File(pngDir, "pic1.png");
Uri pngUri = Uri.fromFile(pngFile);
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.setType("image/png");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ "[email protected]"});
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());
emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, pngUri);
emailIntent.setType("image/png");
EmailActivity.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
}
});
Button camera = (Button) findViewById(R.id.button2);
camera.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
;
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode== 0 && resultCode == Activity.RESULT_OK){
Bitmap x = (Bitmap) data.getExtras().get("data");
((ImageView)findViewById(R.id.imageView1)).setImageBitmap(x);
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.BUCKET_ID, "test");
values.put(Images.Media.DESCRIPTION, "test Image taken");
values.put(Images.Media.MIME_TYPE, "image/png");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
OutputStream outstream;
try {
outstream = getContentResolver().openOutputStream(uri);
x.compress(Bitmap.CompressFormat.JPEG, 70, outstream);
outstream.close();
} catch (FileNotFoundException e) {
//
}catch (IOException e){
//
}
} }
}
.
Sadece denedim ve bu benim için çalıştı deneyin yardımcı olur umut! Lütfen kabul edin :) – Beast
Teşekkür ederiz! Mükemmel çalışıyor! – PaulH
Sadece bir şey keşfetti. E-postayı şimdi çekilmiş bir fotoğraf olmadan göndermez. Bir resim çekilmediyse e-postayı göndermeye hala var mı? – PaulH