【问题标题】:Notification does not show on 2.3.6 [duplicate]通知未在 2.3.6 上显示 [重复]
【发布时间】:2013-02-18 13:48:27
【问题描述】:

我的程序正在从服务调用此代码以显示通知:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(icon)
        .setContentTitle("BU").setOngoing(true).setContentText("BU is the biggest!!!");
  mNM.notify(mNotificationId, mBuilder.build());

它适用于具有 4.1+ 版本的 Galaxy S-III,但它在 android v2.3.6 上也没有出现错误。

我已经阅读了 api,但我可能会遗漏一些东西。有什么问题,我该如何解决?

提前谢谢...

【问题讨论】:

    标签: android notifications


    【解决方案1】:

    试试这个代码,因为它对我有用(2.2 及更高版本)。我在我创建的单独服务类中运行此方法。发现我的通知在没有后台服务的情况下无法工作。

        final NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        final Notification notification = new Notification(R.drawable.notification_popup, message, System.currentTimeMillis());
    
        // used to call up this specific intent when you click on the notification
        final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, 
                new Intent(context, MyActivity.class), Notification.FLAG_AUTO_CANCEL);
    
        notification.setLatestEventInfo(context, title, message, contentIntent);
        notification.defaults = Notification.DEFAULT_ALL;
        manager.notify(new Random(100).nextInt(), notification);
    

    【讨论】:

    【解决方案2】:

    试试Notification Compat 2。它已被开发用于处理此类问题。

    【讨论】:

    • 我猜由于最后一个支持库,它已被弃用。
    【解决方案3】:

    来自官方文档Android

    此类需要 API 级别 11 或更高。

    此文档已隐藏,因为您为 文档为 10。您可以使用以下命令更改文档 API 级别 左侧导航上方的选择器。

    如需详细了解如何指定您的应用所需的 API 级别, 阅读支持不同的平台版本。

    要在page 的左侧确认此选择 api 级别 10,您将弹出此对话框

    【讨论】:

    • 问题是我没有使用 NotificationBuilder,检查我的代码,我使用的是 NotificationCompat.Builder。
    猜你喜欢
    • 2021-09-29
    • 1970-01-01
    • 2018-12-23
    • 2015-03-07
    • 1970-01-01
    • 2021-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多