How to rate google play app in application?

I want to rate my application directly in my app how can i make this?
Device.OpenUri(new Uri("details?id=packagename"));
with this i open in browser but i want to rate directly inside of the app

Best Answer

Answers

  • LearnEverythingLearnEverything USMember ✭✭✭

    This code for Android

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    using Android.App;
    using Android.Content;
    using Android.Content.PM;
    using Android.OS;
    using Android.Runtime;
    using Android.Views;
    using Android.Widget;
    
    namespace XamarinAndroid.Basic.Helpers
    {
        public class SupportHelper
        {
            public static void RateAndReview(Context context, string packageName = null)
            {            
                var url = $"market://details?id={context?.PackageName}";
    
                try
                {
                    context.PackageManager.GetPackageInfo("com.android.vending", PackageInfoFlags.Activities);
                    Intent intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(url));
    
                    context.StartActivity(intent);
                }
                catch (PackageManager.NameNotFoundException ex)
                {
                    // this won't happen. But catching just in case the user has downloaded the app without having Google Play installed.
    
                    Console.WriteLine(ex.Message);
                }
                catch (ActivityNotFoundException)
                {
                    // if Google Play fails to load, open the App link on the browser 
                    if (!string.IsNullOrEmpty(packageName))
                    {
                        var playStoreUrl = "https://play.google.com/store/apps/details?id=" + packageName; //Add here the url of your application on the store
                        var browserIntent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(playStoreUrl));
                        browserIntent.AddFlags(ActivityFlags.NewTask | ActivityFlags.ResetTaskIfNeeded);
                        context.StartActivity(browserIntent);
                    }
                }
            }
        }
    }
    
Sign In or Register to comment.