Мы разрабатываем приложение Xamarin.Forms. На стороне Android я пытаюсь реализовать широковещательный приемник для намерения «android.intent.action.MY_PACKAGE_REPLACED», чтобы мы могли убедиться, что он зарегистрирован в GCM после обновления. Я добавил в него уведомление, чтобы убедиться, что код был поражен, но он не отображается. Любой совет? Код будет ниже. Я развертываю от VS до своего Samsung Galaxy s5 на Android 6.0.Внедрение широковещательного приемника «android.intent.action.MY_PACKAGE_REPLACED» не работает в Xamarin
[BroadcastReceiver(Permission = "com.google.android.c2dm.permission.SEND", Exported = true)]
[IntentFilter(new string[] { Intent.ActionMyPackageReplaced }, DataPath = "<package name>", DataScheme = "package")]
public class GCMUpdateReceiver : GcmReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Bundle bundle = intent.Extras;
var notificationBuilder = new Notification.Builder(Application.Context)
.SetSmallIcon(Resource.Drawable.icon)
.SetContentTitle("OnReceive")
.SetContentText("ActionMyPackageReplaced")
.SetAutoCancel(true);
var notificationManager = (NotificationManager)Application.Context.GetSystemService(Context.NotificationService);
notificationManager.Notify(0, notificationBuilder.Build());
}
}
отметить: Я сделал чистым перед нажатием, чтобы убедиться, что проект построен и должен рассматриваться в качестве обновления.