Delen via


ContactMessageActivatedEventArgs Class

Definition

Provides data when an app is activated to send a message to a contact.

JavaScript This type appears as WebUIContactMessageActivatedEventArgs.

public ref class ContactMessageActivatedEventArgs sealed : IActivatedEventArgs, IContactMessageActivatedEventArgs
/// [Windows.Foundation.Metadata.ContractVersion(Windows.ApplicationModel.Activation.ContactActivatedEventsContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ContactMessageActivatedEventArgs final : IActivatedEventArgs, IContactMessageActivatedEventArgs
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.ApplicationModel.Activation.ContactActivatedEventsContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ContactMessageActivatedEventArgs : IActivatedEventArgs, IContactMessageActivatedEventArgs
Public NotInheritable Class ContactMessageActivatedEventArgs
Implements IActivatedEventArgs, IContactMessageActivatedEventArgs
Inheritance
Object Platform::Object IInspectable ContactMessageActivatedEventArgs
Attributes
Implements

Windows requirements

Device family
Windows Desktop Extension SDK (introduced in 10.0.10240.0)
API contract
Windows.ApplicationModel.Activation.ContactActivatedEventsContract (introduced in v1.0)

Examples

Here is an example of the code you need to handle contact message activations for PSTN numbers and Skype Ids.

protected override void OnActivated(IActivatedEventArgs args)
{
    if (args.Kind == ActivationKind.Contact)
    {
        var contactArgs = args as IContactActivatedEventArgs;
        if (contactArgs.Verb == Windows.ApplicationModel.Contacts.ContactLaunchActionVerbs.Message)
        {
            IContactMessageActivatedEventArgs messageArgs = contactArgs as IContactMessageActivatedEventArgs;

            //get contact display info
            var contactName = messageArgs.Contact.DisplayName;
            var contactThumbnail = messageArgs.Contact.Thumbnail;

            if (messageArgs.ServiceId == "telephone")
            {
                var phoneNumber = messageArgs.ServiceUserId;
                //add messaging logic for PSTN numbers
            }
            else if (messageArgs.ServiceId == "skype.com")
            {
                var userId = messageArgs.ServiceUserId;
                //add messaging logic for Skype Ids
            }
        }
    }
}
void App::OnActivated(Windows::ApplicationModel::Activation::IActivatedEventArgs const& args)
{
    if (args.Kind() == Windows::ApplicationModel::Activation::ActivationKind::Contact)
    {
        auto contactArgs{ args.as<Windows::ApplicationModel::Activation::IContactActivatedEventArgs>() };
        if (contactArgs.Verb() == Windows::ApplicationModel::Contacts::ContactLaunchActionVerbs::Message())
        {
            auto messageArgs{ contactArgs.as<Windows::ApplicationModel::Activation::ContactMessageActivatedEventArgs>() };

            // Get contact display info.
            auto contactName{ messageArgs.Contact().DisplayName() };
            auto contactThumbnail{ messageArgs.Contact().Thumbnail() };

            if (messageArgs.ServiceId() == L"telephone")
            {
                auto phoneNumber = messageArgs.ServiceUserId();
                // Add messaging logic for PSTN numbers.
            }
            else if (messageArgs.ServiceId() == L"skype.com")
            {
                auto userId = messageArgs.ServiceUserId();
                // Add messaging logic for Skype Ids.
            }
        }
    }
}
void App::OnActivated(IActivatedEventArgs^ args)
{
    if (args->Kind == ActivationKind::Contact)
    {
        auto contactArgs = dynamic_cast<IContactActivatedEventArgs^>(args);
        if (contactArgs->Verb == Windows::ApplicationModel::Contacts::ContactLaunchActionVerbs::Message)
        {
            auto messageArgs = dynamic_cast<ContactMessageActivatedEventArgs^>(contactArgs);

            //get contact display info
            auto contactName = messageArgs->Contact->DisplayName;
            auto contactThumbnail = messageArgs->Contact->Thumbnail;

            if (messageArgs->ServiceId == "telephone")
            {
                auto phoneNumber = messageArgs->ServiceUserId;
                //add messaging logic for PSTN numbers
            }
            else if (messageArgs->ServiceId == "skype.com")
            {
                auto userId = messageArgs->ServiceUserId;
                //add messaging logic for Skype Ids
            }
        }
    }
}

Remarks

Windows 8.1 allows users to message their contacts from the Contact Card or Windows Search experience. By implementing the contact message activation contract, Windows can launch your app to send messages for the user.

To receive message activations, your app must register for the "windows.contact" extension category in its manifest. Under this extension, you must include a "LaunchAction" element with the "Verb" attribute equal to "message." You can then specify the "ServiceId" element to specify the type of messaging you support. For example, if your app handles standard text messages, you can specify a "ServiceId" of "telephone." If your app handles messaging over a web based service, like Skype, you can specify the domain name of that service, for example "skype.com."

If multiple apps have registered for this contract, the user can choose one of them as their default for handling messages.

Here is an example for manifest registration.

<m2:Extension Category="windows.contact" xmlns:m2="http://schemas.microsoft.com/appx/2013/manifest">
  <m2:Contact>
    <m2:ContactLaunchActions>
      <m2:LaunchAction Verb="message" DesiredView="useLess">
        <m2:ServiceId>telephone</m2:ServiceId>
      </m2:LaunchAction>
      <m2:LaunchAction Verb="message" DesiredView="useLess">
        <m2:ServiceId>skype.com</m2:ServiceId>
      </m2:LaunchAction>
    </m2:ContactLaunchActions>
  </m2:Contact>
</m2:Extension>

After you register in your manifest, your app can be activated for the contact message contract. When your app is activated, you can use the event information to identify the message activation and extract the parameters that help you complete the messaging scenario for the user.

For info about how to handle app activation through contact actions, see Quickstart: Handling contact actions .

Properties

Contact

Gets the contact for the message.

Kind

Gets the activation type.

PreviousExecutionState

Gets the execution state of the app before it was activated.

ServiceId

Gets the identifier of the service used for the message.

ServiceUserId

Gets the user identifier of the service used for the message.

SplashScreen

Gets the splash screen object, which provides information about the transition from the splash screen to the activated app.

Verb

Gets the action to be performed.

Applies to

See also