更新时间:2023-11-21 23:20:10
Android
项目中不需要创建新的 ITextRecognition
接口,你应该使用您在 Xamarin.forms
项目中创建的界面.
You don't need to create a new ITextRecognition
interface in Android
project, you should use the interface which you created in the Xamarin.forms
projet.
另外,***不要在 FoodMenu 类中创建接口.
Also, it's better not to create the interface inside the FoodMenu class.
代码示例如下:
在 Xamarin.Forms 中:
In Xamarin.Forms:
namespace App384
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class FoodMenu : ContentPage
{
public FoodMenu()
{
InitializeComponent();
}
public void Food_CameraEntry(object sender, EventArgs e)
{
Xamarin.Forms.DependencyService.Register<ITextRecognition>();
DependencyService.Get<ITextRecognition>().LaunchActivityInAndroid();
}
}
public interface ITextRecognition
{
void LaunchActivityInAndroid();
}
}
在 Xamarin.Android 项目中:
In Xamarin.Android project:
[assembly: Xamarin.Forms.Dependency(typeof(TextRecognition))]
namespace App384.Droid
{
[Preserve(AllMembers = true)]
[Activity(Label = "TextRecognition", Theme = "@style/Theme.AppCompat.Light.NoActionBar", MainLauncher = true)]
public class TextRecognition : AppCompatActivity, ITextRecognition
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
}
public void LaunchActivityInAndroid()
{
Console.WriteLine("LaunchActivityInAndroid");
}
}
}
我已经上传了这里的测试演示,您可以查看.
I have uploaded test demo here and you can check.