How do I take a photo and email it?

I want the user to take a photo and then open the email dialog with the photo attached. So far I got this:

private void btnSubmitPhoto_Click(object sender, EventArgs e) 
{ 
    CameraCaptureTask cameraCaptureTask = new CameraCaptureTask(); 
    cameraCaptureTask.Completed += cameraCaptureTask_Completed; 
    cameraCaptureTask.Show(); 
} 

private void cameraCaptureTask_Completed(object sender, PhotoResult e) 
{ 
    if (e.TaskResult == TaskResult.OK) 
    { 
        currentImage = new BitmapImage(); 
        currentImage.SetSource(e.ChosenPhoto); 

        EmailComposeTask ect = new EmailComposeTask();     
    }             
}    

      

I can't see how to add my app to EmailComposeTask. Did I miss something?

+2


source to share


2 answers


It is not possible for current infrastructure tools to add an attachment to an email using EmailComposeTask

. If you need this functionality, you will have to manually handle sending email using the web service.



+8


source


In addition to not being able to send attachments, there is a problem with the way you are using CameraCaptureTask

.

Since this task is a choice, you should use it for the tombsoning account.

In practical terms, this means that the yoour instance CameraCaptureTask

must be at the class level, and the handler for the completed event must also be subscribed to in the page constructor.

If you don't, the page won't know how to handle the information returned when a task is returned.

Your code should look something like this:



public partial class MainPage : PhoneApplicationPage
{
    CameraCaptureTask cct = new CameraCaptureTask();

    public MainPage()
    {
        InitializeComponent();

        // Any other initialization tasks

        cct.Completed += new EventHandler<PhotoResult>(cct_Completed);
    }

    void cct_Completed(object sender, PhotoResult e)
    {
        // Do something with `e`
    }

    // Or some other appropriate event
    private void Button_Click(object sender, RoutedEventArgs e)
    {
        cct.Show();
    }

      

Note. This applies to all selections, but not to launchers.

Update:
The reason for this is that the page is "rehydrated" after the application has been buried to open the selector.

When you return from the selection display, a new instance of the page will be created. Therefore, this will not include writing event handler entries subscribed in previous cases. Without binding to a completed handler, your code to handle the details returned by the selection will not be called.

+2


source







All Articles