Use android package manager in Xamarin.Forms

安稳与你 提交于 2021-01-29 11:20:40

问题


Trying to check if a particular application is installed in the android phone or not.

In android studio, I used Package manager to get the installation status of the application. But I need to use Xamarin.Forms for development.


回答1:


yes,you could use DependencyService to achive this:

first,define a Interface :

public interface IsInstallApplication
 {
     bool IsInstall(string packageName);
 }

then in Droid.project create a class which implement the interface :

[assembly: Dependency(typeof(AndroidIsInstallApplication))]// do not miss the line
namespace App18.Droid
{
   class AndroidIsInstallApplication : IsInstallApplication
     {
        public bool IsInstall(string packageName)
         {
            ... //here you could use Package manager to get the installation status of the application like in native android
            return true;
         }
     }
}

finally you could call it in you page like :

DependencyService.Get<IsInstallApplication>().IsInstall(packageName);


来源:https://stackoverflow.com/questions/57566727/use-android-package-manager-in-xamarin-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!