0

我根据通知栏拥有:http: //developer.android.com/guide/topics/ui/notifiers/notifications.html

我喜欢这个教程:

            Notification notification = new Notification();
            notification.flags = Notification.FLAG_ONGOING_EVENT;
            notification.icon = icon;

            RemoteViews contentView = new RemoteViews(getPackageName(),
                    R.layout.custom_notification);
            contentView.setImageViewResource(R.id.image, R.drawable.b_10);
            contentView.setTextViewText(R.id.title, "Custom zgłoszenie");
            contentView.setTextViewText(R.id.text, "test test test");
            notification.contentView = contentView;

            NotificationIntent Intent = new Intent(BatteryInfoService.this,
                    BatteryInfoActivity.class);
            ContentIntent PendingIntent = PendingIntent.getActivity(ta, 0,
                    notificationIntent, 0);
            notification.contentIntent = contentIntent;

            mNotificationManager.notify(BATTERY_ID, notification);

行中有错误:

            NotificationIntent Intent = new Intent(BatteryInfoService.this,
                    BatteryInfoActivity.class);
            ContentIntent PendingIntent = PendingIntent.getActivity(ta, 0,
                    notificationIntent, 0);
            notification.contentIntent = contentIntent;

错误:

NotificationIntent cannot be resolved to a type

Multiple markers at this line
    - ContentIntent cannot be resolved to 
     a type
    - ta cannot be resolved to a variable

contentIntent cannot be resolved to a variable
4

1 回答 1

2

将 NotificationIntent 替换为 Intent(android 不提供 NotificationIntent,除非它是自定义类)。

你要找的是

Intent notificationIntent = new Intent(BatteryInfoService.this,BatteryInfoActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

请仔细阅读教程。Intent 和 PendingIntent 是 Android 类,而 NotificationIntent 和 ContentIntent 不是。如果您在这些名称下创建了自定义类,则可以导入相应的包。

于 2012-09-07T15:07:17.310 回答