1

我正在尝试创建一个应用程序来拍照,然后通过电子邮件发送。最近几天我一直在搞乱我的代码,我尝试了很多不同的东西,但我仍然无法让它工作。我可以拍照没问题,只是当我发送它时我的应用程序崩溃了。请参阅下面的代码:

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);

    }
}

}

当我去发送它时,我收到以下错误:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SEND (has extras)

有人可以帮我吗?谢谢

4

3 回答 3

0

尝试使用这个

startActivityForResult(((Intent.createChooser(emailIntent, "Send mail..."))), 0);
于 2012-08-28T09:48:09.187 回答
0

添加 emailIntent.setType("message/rfc822"); 使用前startActivity(emailIntent);。并使用这个 Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

于 2012-08-28T10:06:56.440 回答
0

看起来您没有合适的应用程序来处理这种意图。尝试创建选择器,这将打开一个与可以处理此类意图的应用程序的对话框。

尝试添加下一行:

使用下一个链接: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"));
于 2012-08-28T09:51:17.807 回答