gpt4 book ai didi

c# - 如何将 android 中的服务意图设置为 Xamarin 跨平台中的共享页面

转载 作者:太空宇宙 更新时间:2023-11-03 12:55:41 24 4
gpt4 key购买 nike

我正在尝试将 Android 通知的返回页面设置为 Xamarin 中的内容页面。也就是说,android 服务发送本地通知,当用户单击该通知时,他将被带到共享的 xamarin.forms 页面。

在下面的代码中,“MyWishList”

是 PCL 中的共享页面,但代码驻留在项目的 Android 版本中。运行这段代码会抛出异常

System.ArgumentException: type Parameter name: Type is not derived from a java type.

当我将 MyWishList 更改为 android 事件时它工作正常,但我需要将通知连接到共享页面。

void sendUserNotification(string title, string username)
{
// Pass the current button press count value to the next activity:
Bundle userDetails = new Bundle();
userDetails.PutString(title, username);

// When the user clicks the notification, SecondActivity will start up.
Intent resultIntent = new Intent(this, typeof(MyWishList)); // change mainActivity to wishlist page pcl

// Pass some values to SecondActivity:
resultIntent.PutExtras(userDetails);

// Construct a back stack for cross-task navigation:
TaskStackBuilder stackBuilder = TaskStackBuilder.Create(this);
stackBuilder.AddParentStack(Java.Lang.Class.FromType(typeof(MainActivity)));
stackBuilder.AddNextIntent(resultIntent);

// Create the PendingIntent with the back stack:
PendingIntent resultPendingIntent =
stackBuilder.GetPendingIntent(0, (int)PendingIntentFlags.UpdateCurrent);

// Build the notification:
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.SetAutoCancel(true) // Dismiss from the notif. area when clicked
.SetContentIntent(resultPendingIntent) // Start 2nd activity when the intent is clicked.
.SetContentTitle("New Notification: " + counter) // Set its title
.SetSmallIcon(Resource.Drawable.zaposta_icon); // Display this icon


// Finally, publish the notification:
NotificationManager notificationManager =
(NotificationManager)GetSystemService(Context.NotificationService);
int notificationId = 0;
notificationManager.Notify(notificationId, builder.Build());
}

最佳答案

我遇到了同样的问题。可能您的“MyWishList”事件是 ViewModel。我设置了 View 并解决了它。

我希望这可以帮助其他人解决同样的问题。

关于c# - 如何将 android 中的服务意图设置为 Xamarin 跨平台中的共享页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34002936/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com