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[] = { "[email protected]", "", };
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);
}
我如何去發送我拍攝的照片?它在哪裏保存,我如何訪問它以便我可以通過電子郵件發送?
非常感謝
當我嘗試使用onActivityResult方法時,獲取以下錯誤:java.lang.RuntimeException:傳遞結果失敗ResultInfo {who = null,request = 0,result = -1,data = Intent {act = inline-data (有額外)}}}活動{com.thenewboston.david/com.thenewboston.david.Camera}:java.lang.NullPointerException。 – DMC