在 Xamarin.Forms 中使用 android 包管理器 [英] Use android package manager in Xamarin.Forms

查看:31
本文介绍了在 Xamarin.Forms 中使用 android 包管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试检查安卓手机中是否安装了特定应用程序.

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

在android studio中,我使用包管理器来获取应用程序的安装状态.但我需要使用 Xamarin.Forms 进行开发.

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

推荐答案

是的,您可以使用 DependencyService 来实现:

yes,you could use DependencyService to achive this:

首先,定义一个接口:

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

然后在Droid.project中创建一个实现接口的类:

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);

这篇关于在 Xamarin.Forms 中使用 android 包管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆