Search code examples
androidandroid-notificationsandroid-notification-bar

Android custom notification bar


I do own according to the notification bar: http://developer.android.com/guide/topics/ui/notifiers/notifications.html

I do like the tutorial :

            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);

There are errors in the lines:

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

Errors:

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

Solution

  • Replace NotificationIntent with Intent (android does not provide NotificationIntent, unless its a custom class).

    what you are looking for is

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

    Please read the tutorial carefully. Intent and PendingIntent are android Classes where as NotificationIntent and ContentIntent are not. If you have made custom classes under those names and you can import the appropriate packages.