【问题标题】:Local notifications not working when app is breaked on Huawei device [Xamarin.Android]应用程序在华为设备上中断时本地通知不起作用 [Xamarin.Android]
【发布时间】:2020-02-25 03:05:14
【问题描述】:

我创建了一个 Xamarin.Forms 应用程序,但我面向的是 android 平台。我已经在 2 台设备上发布了该应用程序:三星(Android 6.0 API 23)和华为(Android 6.0 API 23),问题出在华为设备上,当我想创建一个本地通知时它需要在应用程序中断时显示,(通过创建广播接收器等)它不显示,否则在三星上它是,我确定问题不在代码上(很明显,代码不是专门针对一个特定的设备),所以我更相信问题出在我的华为设备上,对此问题有什么建议吗?

创建通知的代码

当用户点击“通知按钮”时调用的方法来调度重复的通知:

 public static void EstablishNotification(long startSeconds)
            => alarmManager.SetRepeating(
                AlarmType.ElapsedRealtimeWakeup,
                SystemClock.ElapsedRealtime() + (startSeconds * 1000),
                3600 * 1000, pendingIntent);

广播接收器绑定到警报管理器的意图

public override void OnReceive(Context context, Intent intent)
        {
            if (intent?.Extras != null)
            {
                title = intent.Extras.GetString(AndroidNotificationManager.TitleKey);
                message = intent.Extras.GetString(AndroidNotificationManager.MessageKey);
            }

            var id = intent.Extras.GetInt(AndroidNotificationManager.ID);

            Intent _intent = new Intent(AndroidApp.Context, typeof(SplashActivity));
            _intent.PutExtra(TitleKey, title);
            _intent.PutExtra(MessageKey, message);
            _intent.PutExtra(ID, id); 

            PendingIntent pendingIntent = PendingIntent.GetActivity(
                AndroidApp.Context,
                id, _intent,
           PendingIntentFlags.OneShot);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(AndroidApp.Context, channelId)
               .SetContentIntent(pendingIntent)
               .SetContentTitle(title)
               .SetContentText(message)
               .SetLargeIcon(BitmapFactory.DecodeResource(AndroidApp.Context.Resources, Resource.Drawable.SortexAppIcon))
               .SetSmallIcon(Resource.Drawable.SortexAppIcon)
               .SetDefaults((int)NotificationDefaults.Sound | (int)NotificationDefaults.Vibrate);

            manager = 
                (NotificationManager)context.GetSystemService(
                    AndroidApp.NotificationService);

            var notification = builder.Build();
            manager.Notify(messageId, notification);

【问题讨论】:

  • 您创建了通知渠道吗?
  • @AndroDevil 是的
  • 它是否可以在任何其他带有 android 8.0 的设备上运行?
  • @AndroDevil 我还没试过
  • 请在其他安卓8.0的设备上查看。这样我们就可以隔离问题

标签: android xamarin.forms xamarin.android notifications huawei-mobile-services


【解决方案1】:
【解决方案2】:

方法,首先,在手机中找到“设置”,点击进入,找到“通知管理”。二、点击进入“通知管理”,包括“通知管理”和“暂停窗口管理”,显示“通知管理”。 四、在“通知管理”中,找到需要打开的应用程序。点击“进入”,会显示相应的选项,选择“提示”或“允许”。

以下是详细的中文文字和图片介绍, https://zhidao.baidu.com/question/1695787110911971788.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    • 2022-07-27
    • 1970-01-01
    • 2019-06-18
    相关资源
    最近更新 更多