簡體   English   中英

在Xamarin.Forms中使用android包管理器

[英]Use android package manager in Xamarin.Forms

嘗試檢查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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM