Determine Huawei Device

Jassim Al Rahma 1,616 Reputation points
2021-05-16T11:08:36.057+00:00

Hi,

I am using below code to determine if the user is on iPhone or Android but how can I determine if the user is on Huawei AppGallery?

if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.iOS)
{
    Launcher.OpenAsync(App.AppUpdateiOS);
}
else if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.Android)
{
    Launcher.OpenAsync(App.AppUpdateAndroid);
}

Thanks,
Jassim

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,971 Reputation points
    2021-05-17T01:39:17.347+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    but how can I determine if the user is on Huawei AppGallery

    For this function, please try to detect the manufacture of the build device on the native Android. You could use DependencyService to invoke native platform functionality from shared code.

    1.Create an interface for the native platform functionality in the shared project.

       namespace TestApplication  
       {  
           public interface ITestInterface  
           {  
               string getPath();  
           }  
       }  
    

    2.Implement the interface in the required platform projects and register the platform implementations.

       [assembly: Xamarin.Forms.Dependency(typeof(TestImplementation))]  
       namespace TestApplication.Droid  
       {  
           public class TestImplementation : ITestInterface  
           {  
               public string getManufacturer()  
               {  
                   string deviceMan = Android.OS.Build.Manufacturer; ;  
                   return deviceMan;  
               }  
           }  
       }  
    

    3.Consume the code in the shared project to the get manufacture of the build device.

       var deviceMan = DependencyService.Get<ITestInterface>().getManufacturer();  
       if (deviceMan == "HUAWEI")  
       {  
           //perform the work  
       }  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.