-1

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

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,但我可能会错过一些东西。有什么问题,我该如何解决?

提前致谢...

4

3 回答 3

0

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

于 2013-03-04T13:09:30.777 回答
0

试试这个代码,因为这对我有用(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);
于 2013-03-04T13:09:55.553 回答
0

来自官方文档Android

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

This document is hidden because your selected API level for the documentation is 10. You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

to confrim this select api level 10 from left side on the page you will get this dialog poped up

于 2013-03-04T13:10:03.660 回答