0

我根据通知栏自己:http://developer.android.com/guide/topics/ui/notifiers/notifications.htmlAndroid的自定义通知栏

我喜欢的教程:

  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 
+1

把意图,而不是NotificationIntent。 –

+0

它没有帮助。 – Defuzer

回答

2

用Intent替换NotificationIntent(android不提供NotificationIntent,除非它的自定义类)。

你正在寻找的是

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

请仔细阅读本教程。 Intent和PendingIntent是Android类,其中NotificationIntent和ContentIntent不是。如果您已经在这些名称下创建了自定义类,并且您可以导入适当的包。

+0

类型PendingIntent中的方法getActivity(Context,int,Intent,int)不适用于参数(新的BroadcastReceiver(){},int,Intent,int) – Defuzer

+0

好的。有用。必须是name_class.this – Defuzer

+1

尝试“MyClass.this”而不是“this”,如果您在广播接收器中使用它。这是你将正确传递活动的上下文。 – Gan