0

我正在尝试创建一个应用程序,您可以在其中拍照然后通过电子邮件将其发送给某人。目前我可以拍照并将我的背景设置为这张照片:

public class Camera extends Activity implements View.OnClickListener{


ImageButton ib;
Button b;
ImageView iv;
Intent i;
final static int cameraData = 0;
Bitmap bmp;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.photo);
    initialize();
    InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
    bmp = BitmapFactory.decodeStream(is);
}

private void initialize(){
    ib = (ImageButton) findViewById(R.id.ibTakePic);
    b = (Button) findViewById(R.id.bSetWall);
    iv = (ImageView) findViewById(R.id.ivReturnedPic);
    b.setOnClickListener(this);
    ib.setOnClickListener(this);



}

@Override
public void onClick(View v) {
    File mImageFile;
    // TODO Auto-generated method stub
    switch(v.getId()){
    case R.id.bSetWall:
        try {
            getApplicationContext().setWallpaper(bmp);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    break;
    case R.id.ibTakePic:
        i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, cameraData);
    break;
    }

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == RESULT_OK){
        Bundle extras = data.getExtras();
        bmp = (Bitmap)extras.get("data");
        iv.setImageBitmap(bmp);
    }
}




}

我有一个单独的应用程序,我可以在其中接收用户输入并将其通过电子邮件发送到预定义的地址:

    public void onClick(View v) {
    // TODO Auto-generated method stub
    convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated();
    String emailaddress[] = { "info@sklep.com", "", };
    String message = emailAdd + name + beginning;

    Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);

    emailIntent.setType("plain/text");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
    startActivity(emailIntent);

}

如何通过电子邮件发送我拍摄的照片?它保存在哪里以及如何访问它以便我可以通过电子邮件发送它?

非常感谢

4

2 回答 2

1
 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == RESULT_OK){
    File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
                File output = new File(dir, "camerascript.png");
                cPath = output.getAbsolutePath();
                Bitmap b =  BitmapFactory.decodeFile(cPath);
                Bitmap out = Bitmap.createScaledBitmap(b, 320, 480, false);
                FileOutputStream fout;
                try{
                    fout = new FileOutputStream(output);
                    out.compress(Bitmap.CompressFormat.PNG, 100, fout);
                    fout.flush();
                    fout.close();
                    b.recycle();
                    out.recycle();
                }catch(Exception e){
                    e.printStackTrace();
                }

        }
    }

之后在您的发送邮件方法中

public void sendMail(){
        Log.e("sendMail", "v r in sendMail");

        i = new Intent(Intent.ACTION_SEND);
        i.setType("plain/text");
            i.putExtra(Intent.EXTRA_EMAIL, new String[] {"abc@gmail.com"});
          i.putExtra(Intent.EXTRA_SUBJECT,"subject...");
        i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(cPath));
        i.putExtra(Intent.EXTRA_TEXT, "Body of Email....");
        startActivityForResult(Intent.createChooser(i, "send mail...."),EMAIL_SUCCESS);

    }

上面的代码将帮助你..

于 2012-08-23T14:37:39.900 回答
0
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode == RESULT_OK){
     Uri uri=data.getData();
     sendmail(uri);

}

and 
  private void sendmail(Uri uri)
  {
    i = new Intent(Intent.ACTION_SEND);
    i.setType("plain/text");
    i.putExtra(Intent.EXTRA_EMAIL, new String[] {"abc@gmail.com"});
    i.putExtra(Intent.EXTRA_SUBJECT,"subject...");
    i.putExtra(Intent.EXTRA_STREAM, uri);
     i.putExtra(Intent.EXTRA_TEXT, "Body of Email....");
   startActivityForResult(Intent.createChooser(i, "send mail...."),EMAIL_SUCCESS);

  }

它可能有效。

于 2012-08-23T15:05:53.180 回答