Я следую этому руководству по реализации приложения, использующего бесконтактный маяк:
https://github.com/Estimote/Xamarin-Bindings
Я скачал папку ExampleApp из github и установил 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
в этом классе я не узнаю это.Как я могу решить эту проблему?