c# - 在 Xamarin.Forms 中使用 android 包管理器
问题描述
尝试检查特定应用程序是否安装在 android 手机中。
在android studio中,我使用包管理器来获取应用程序的安装状态。但我需要使用 Xamarin.Forms 进行开发。
解决方案
是的,您可以使用DependencyService来实现:
首先,定义一个接口:
public interface IsInstallApplication
{
bool IsInstall(string packageName);
}
然后在Droid.project创建一个实现接口的类:
[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;
}
}
}
最后你可以在你的页面中调用它:
DependencyService.Get<IsInstallApplication>().IsInstall(packageName);
推荐阅读
- python - 删除pygame上的图像
- influxdb - 通过 telegraf 传递多个代理以将数据发送到 influx
- javascript - 扫雷炸弹威胁
- c# - C# 中的 BMI 计算器关于提取先前键入的数据的问题
- amazon-web-services - aws cloudformation - 在我的 vpc 中启动 ec2 实例
- reactjs - 如何使用borderRadius在本机反应中圆角?
- java - Spring Kafka:按顺序阅读两个不同的主题
- java - onTouch() 未触发
- java - Android:未找到 setTextTypeFace 字体资源
- python-3.x - 从 Azure Databricks 读取 Azure Datalake Gen2 映像