Android自定义通知栏

Android自定义通知栏,android,android-notifications,android-notification-bar,Android,Android Notifications,Android Notification Bar,根据通知栏,我确实拥有: 我很喜欢这个教程: Notification notification = new Notification(); notification.flags = Notification.FLAG_ONGOING_EVENT; notification.icon = icon; RemoteViews contentView = new RemoteViews(getPacka

根据通知栏,我确实拥有:

我很喜欢这个教程:

            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

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

你要找的是

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

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

put Intent而不是NotificationIntent。PendingContent类型中的方法getActivity(Context,int,Intent,int)不适用于参数(new BroadcastReceiver(){},int,Intent,int)。如果在广播接收器内使用此方法,请尝试“MyClass.this”而不是“this”。这意味着您将正确传递活动的上下文。