在其他类中扩展mainActivity

时间:2019-09-28 14:14:01

标签: c# xamarin xamarin.forms xamarin.android beacon

我正在按照本指南实施使用邻近信标的应用程序:

https://github.com/Estimote/Xamarin-Bindings

我从github下载了ExampleApp文件夹并安装了Estimote.Android.Proximity。很好。

但这是我的问题:

namespace Example.Android.Proximity
{
    [Activity(Label = "Proximity", MainLauncher = true)]
    public class MainActivity : Activity
    {

        IProximityObserver observer;
        IProximityObserverHandler observationHandler;
        IProximityZone zone;

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);
            CreateNotificationChannel();

编写代码CreateNotificationChannel()之后。 (我在OnCreate之外编写了代码)

void CreateNotificationChannel(string messagebody, string title)
{
    var intent = new Intent(this, typeof(Activity));
    intent.AddFlags(ActivityFlags.ClearTop);
    var pendingIntent = PendingIntent.GetActivity(this, 0, intent, PendingIntentFlags.OneShot);

    //if i want more than one notification ,different unique value in every call
    if (Build.VERSION.SdkInt < BuildVersionCodes.O)
    {
        string channelName = Resources.GetString(Resource.String.app_name);
        NotificationCompat.Builder notificationBuilder;
        notificationBuilder = new NotificationCompat.Builder(this, channelName)
            .SetContentTitle(title)
            .SetContentText(messagebody)
            .SetAutoCancel(true);

    var notificationManager = GetSystemService(Context.NotificationService) as NotificationManager;
    NotificationChannel channel = new NotificationChannel(channelName, "notification channel", NotificationImportance.Default);
    notificationManager.CreateNotificationChannel(channel);
    notificationManager.Notify(MainActivity.NOTIFICATION_ID, notificationBuilder.Build());
}

我想在另一个类中,特别是在这个类中调用此函数

public class MyEnterHandler : Activity , Kotlin.Jvm.Functions.IFunction1
{
    Java.Lang.Object Invoke(Java.Lang.Object p0)
    {
        IProximityZoneContext context = (IProximityZoneContext)p0;
        string deskOwner = context.Attachments["desk-owner"];
        string description = context.Attachments["description"];
        string image = context.Attachments["image"];
        Log.Debug("app", $"benvenuto nel beacon situato {deskOwner}" +
            $" ed è di colore {description}," +
            $" {image}");
        return null;
    }

如果我想在此类中传递函数CreateNotificationChannel, 我不认识 我该如何解决这个问题?

0 个答案:

没有答案