Sdílet prostřednictvím


How to include "Rate & Review" API in your Windows 8 apps By Walaa Atef

For original post please refer to https://blogs.msdn.com/b/walaa/archive/2013/08/28/ask-users-for-feedback.aspx

 

 

One of the out-of-the-box mechanisms that's available in Windows Store Apps, is the "Rate & Review" option given to app users to send their feedback to the app publishers, and to other prospect users too.

Unfortunately a small percentage of those who download and use an application would give feedback, unless your app is extremely good (or bad), missing a feature that everybody is craving for, the odds are you are going to get few number of reviews.

You can increase the chances to get feedback from users by reminding them to do so. But you have to take care not to be too nagging, to the extent to push them away from your app.

Here is how you can do it. (all code is in the main page of your application).

First we need a couple of member variables/references to local and roaming storage where we are going to save a setting whether we should ask the user for feedback or not.

ApplicationDataContainer _roamingData = ApplicationData.Current.RoamingSettings;

ApplicationDataContainer _localData = ApplicationData.Current.LocalSettings;

It's a good idea to check for Internet connectivity before asking the user to submit his feedback, obviously he won't be able to access the store app to do so, if there is no connectivity.

For this I use the following method.

public static bool CheckInternetConnectivity()
{
        var internetProfile = NetworkInformation.GetInternetConnectionProfile();
        if(internetProfile == null)
        return false;

        return (internetProfile.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess);
}

 The following are helper methods to save and read the setting from local/roaming storage.

I write to both storage, you might opt for using only one of them, and when reading back data, I read first from the local storage, and if not found I attempt to read from the roaming one.

private bool ReadAppRatingSetting()
{
        if (_localData.Values["AppRatingDone"] != null)
        return (bool)_localData.Values["AppRatingDone"];

        if (_roamingData.Values["AppRatingDone"] != null)
        return (bool)_roamingData.Values["AppRatingDone"];

        return false;
}

private void SaveAppRatingSetting()
{
        // for this setting, it's either saved or not, so we save true as the default value
        _localData.Values["AppRatingDone"] = true;
        _roamingData.Values["AppRatingDone"] = true;

}

 And here is the main method which displays the popup dialog which asks the user for feedback, and act accordingly.

private async Task AskForAppRating()
{
        if (!CheckInternetConnectivity())
        return;

        if (ReadAppRatingSetting())
        return;

        MessageDialog msg;
        bool retry = false;
        msg = new MessageDialog("Kindly, help us provide a better service, would you like to review & rate \"THIS APP\"?");
        msg.Commands.Add(new UICommand("Rate", new UICommandInvokedHandler(this.OpenStoreRating)));
        msg.Commands.Add(new UICommand("Not now", (uiCommand) => { }));
        msg.Commands.Add(new UICommand("No, thanks", new UICommandInvokedHandler(this.IgnoreRating)));
        msg.DefaultCommandIndex = 0;
        msg.CancelCommandIndex = 1;
        await msg.ShowAsync();

        while (retry)
        {
        try{ await msg.ShowAsync();}
        catch (Exception ex){}
        }
}

private void IgnoreRating(IUICommand command)
{
        SaveAppRatingSetting();
}

// Launches the store app, using the application storeID
private async void OpenStoreRating(IUICommand command)
{
        await Windows.System.Launcher.LaunchUriAsync(newUri("ms-windows-store:REVIEW?PFN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"));

        SaveAppRatingSetting();

}

 Finally you will need to call AskForAppRating() at the end of the LoadState() method, or any other event fired after page is loaded.