WLA: Detect if user can't launch an Activity

Today we're gonna talk about MSN Messenger Activities stuff. Using activities from Buddyscript means adding handlers in the form of overriden procedures, creating a mini-communication framework (the SDK contains a good example to start from), plus all the code we want to add to make our code more robust and handle possible errors.
I'll focus on detecting and handling problems when for whatever reason the user can't launch an activity.

To use the following code, you must reference lib:/Shared/Utilities/WLMActivityUtilities.pkg, don't forget to ;)

First of all, we can detect if the activity is already launched or not. To do this, BuddyScript has the MSNSLPP4ApplicationIsAvailable() function. I always have additional flags to reflect the action I want the activity to perform when is ready, the state in which it is,... so it's a good idea to wrap this function in another one containing your custom checks too.

If, for some reason the user can't launch the activity, the MSNSLPUserCanNotOpenP4Window() procedure will be called, so you must place an override too in your code, reseting all flags and handling this "disaster".

If the user refuses explicitly to launch the activity, the raised procedure is MSNSLPUserRejectedInvitationToOpenP4Window().

The main call to launch the activity is MSNSLPSendInvitationToOpenP4Application("activityID", "activityName"), but it is a good practice to wrap it in another procedure to check first if user can't launch it, and to avoid having to write the ID and name of the desired activity.

And finally we get into the interesting things. What if the client is running a Web Messenger? Or Messenger from a PDA? Or an old version which can't handle Activities?

With the following code, you can detect all that, and by checking it before launching the activity, avoid most problems and redirect to the "user doesn't supports activities" code fork:

// Checks if the client is on a mobile device, on Web Messenger, or has an old msgr version
function ClientSupportsActivities()
if !Exist(SYS.History[0].Query.ExtraInfo.ClientId)
return false
CLIENTID = SYS.History[0].Query.ExtraInfo.ClientId
if (CLIENTID & 512) != 0 || (CLIENTID & 1) != 0 || (CLIENTID & 4026531840) < 1073741824
return false
else
return true

Comments?

Posted by Kartones on 2007-10-02