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