如何在Xamarin Android项目中从Java库绑定服务


  • 我在Example.aar 中实现了服务类

    公共类DemoService:服务{}

  • 我创建了一个Native绑定库项目。

  • 当我试图在Xamarin绑定此服务时。Android项目。bindService((返回false。

    var Result =context.getApplicationContext.bindService(new Intent(context,typeof(DemoService)), new ServiceConnection(),Bind.AutoCreate); //Result is false.
    

如何在Xamarin Android项目中绑定在第三方库项目中创建的服务。??

您可以参考本文绑定Java库。在Microsoft文档中,首先可以从.aar文件中获取类。

var ClassName = new Com.MyCompany.MyProject.MyclassName();

然后使用bindService或其他方法来使用该类。

var Result =context.getApplicationContext.bindService(new Intent(context,typeof(ClassName)), new ServiceConnection(),Bind.AutoCreate);

最新更新