Android拍照和发送电子邮件

时间:2013-06-01 16:29:46

标签: android email image

我正在尝试创建一个Android应用程序,我可以使用相机拍照并通过电子邮件发送。我浏览了这个网站,但找不到可以让应用程序工作的修复程序。这是我的代码:

    @Override
    public void onClick(View arg0){
        Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);  

    }
    });

    send.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0){

        Intent i = new Intent(Intent.ACTION_SEND);
        i.putExtra(Intent.EXTRA_EMAIL, new String[]{"fake@fake.edu"});
        i.putExtra(Intent.EXTRA_SUBJECT,"On The Job");
        //Log.d("URI@!@#!#!@##!", Uri.fromFile(pic).toString() + "   " + pic.exists());
        //i.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(pic));

        i.setType("image/png");
        startActivity(Intent.createChooser(i,"Share you on the jobing"));
    }
    });

}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
if (requestCode == CAMERA_PIC_REQUEST) {  
 thumbnail = (Bitmap) data.getExtras().get("data");  
ImageView image = (ImageView) findViewById(R.id.imageView1);  
image.setImageBitmap(thumbnail);


    try {
        File root = Environment.getExternalStorageDirectory();
        if (root.canWrite()){
             pic = new File(root, "pic.png");
            FileOutputStream out = new FileOutputStream(pic);
            thumbnail.compress(CompressFormat.PNG, 50, out);
            out.flush();
            out.close();
        }
    } catch (IOException e) {
        Log.e("BROKEN", "Could not write file " + e.getMessage());
    }   

}  

} }

0 个答案:

没有答案