Android: Error al tomar una foto y enviarla por correo electrónico
Frecuentes
Visto 248 veces
1
I am trying to create an application to take a picture and then email it. I have spent the last few days messing around with my code and I have tried lots of different things and I still cant get it working. I can take a picture no problem its just when I go to send it my application crashes.Please see my code below:
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.bSendPic);
iv = (ImageView) findViewById(R.id.ivReturnedPic);
b.setOnClickListener(this);
ib.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bSendPic:
String emailaddress[] = { "info@sklep.com", "", };
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, emailaddress);
// getPackageName() is your app package
Uri path = Uri.parse("android.resource://" + getPackageName()
+ "/ + R.drawable.ic_launcher");
emailIntent.putExtra(Intent.EXTRA_STREAM, path); // Replace your
// line
emailIntent.setType("image/png");
startActivity(Intent.createChooser(emailIntent, "Send Mail"));
/*
* emailIntent.setType("image/jpeg");
*
* emailIntent.putExtra(Intent.EXTRA_STREAM, bmp);
*
* emailIntent.setType("message/rfc822");
* startActivity(Intent.createChooser(emailIntent, "Send Mail"));
*/
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");
bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.ic_launcher);
}
}
}
When I go to send it I get the following error:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND (has extras)
Can someone please help me with this? Thanks
3 Respuestas
0
Add
emailIntent.setType("message/rfc822"); before using startActivity(emailIntent);
.
and use this also
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
Respondido 28 ago 12, 11:08
I tried that but Im still getting The application Gmail(process com.google.adnroid.gm)has stopped unexpectedly. Please try again - DMC
Then it seems you didnt configure any email application like email or anything else. first make sure you have configured any mail account. - Raman
I have configured my email account.I just sent a test email there from my phone and it works perfectly - DMC
0
It looks like you don't have the appropriate app to handle this kind of intent. Try instead to create chooser, this will open a dialog with the application that can deal with such intent.
Try to add the next lines:
use the next link: getPackageName
//getPackageName() is your app package
Uri path = Uri.parse("android.resource://"+ getPackageName() +"/ + R.drawable.ic_launcher");
emailIntent.putExtra(Intent.EXTRA_STREAM, path ); //Replace your line
emailIntent.setType("image/png");
startActivity(Intent.createChooser(emailIntent, "Send Mail"));
Respondido 28 ago 12, 11:08
I tried this and this then gives me the option to select gmail but then it crashes once I select it! - DMC
The application Gmail(process com.google.adnroid.gm)has stopped unexpectedly. Please try again - DMC
I just tried that there and its still crashing. Is it really that tricky to take a picture and send it with android?Am I approaching it the wrong way? - DMC
I think the problem is that you trying to send image that is in your drawable folder. Try to save your image in the internal memory of the device and then send it. pay attention, you still need to use a Content Provider to take that picture from your app to the email app. - Ofir A.
Tried that and still same error. I have updated my code above with your code. Did you mean to put uri instead of path at the end of emailIntent.putExtra? - DMC
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas android android-intent or haz tu propia pregunta.
It looks like you don't have any default app that supports email sending action. Did you check your phone for any such app? - Andro Selva
Yeah I have already designed an app just to send normal emails but when I try and add a picture it doesnt work - DMC
You didn't take a picture. I think the issue is the attachment. Could you try this to initialize the Bitmap:
bmb = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
- iTurkiI tried that and it still crashes when I select gmail to send the email! - DMC