问题
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