我目前正在编写一个应用程序,在某项活动中,我们希望用户能够将照片和电子邮件发送到所需的电子邮件地址。我能够分别做这两件事(拍照和发照片),但是当我一起运行时,电子邮件客户端列表出现在相机上......我似乎无法弄清楚为什么它没有运行在相机本身之后..有任何帮助吗?
***这就是我现在所拥有的:
public class PhotoHandler extends Activity {
private final static int TAKE_PHOTO_CODE = 1;
File downloadedPic = null;
Intent in;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mnwv_main);
downloadedPic = takeandReturn(this);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
try {
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));
picMessageIntent.putExtra(Intent.EXTRA_EMAIL , new String[]{});
picMessageIntent.putExtra(Intent.EXTRA_SUBJECT, "MNWV - Check Out This Photo!");
picMessageIntent.putExtra(Intent.EXTRA_TEXT , "*** Please Describe the Photo Taken Below (Include Your Name, Location, etc.)... ***");
startActivity(Intent.createChooser(picMessageIntent, "Send Picture Using: "));
} catch (Exception e) {
Log.e("TAG", "sendPictureMessage() failed to start activity.", e);
Toast.makeText(this, "No handler", Toast.LENGTH_LONG).show();
}
}
答案 0 :(得分:2)
您必须使用startActivityForResult拍摄照片。之后,您必须使用onActivityResult发送电子邮件:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
// TODO: Test for requestCode and resultCode
try {
Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);
picMessageIntent.setType("image/jpeg");
picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));
startActivity(Intent.createChooser(picMessageIntent, "Send Picture Using: "));
} catch (Exception e) {
Log.e("TAG", "sendPictureMessage() failed to start activity.", e);
Toast.makeText(this, "No handler", Toast.LENGTH_LONG).show();
}
}
希望它会有所帮助。