2015-09-14 146 views
4

我正在Android Studio中工作並嘗試在特定日期和時間生成通知。所有的都是正確的,但是,在我的服務類setLatestEventInfo()方法無法解析。 我在Eclipse中完成了相同的演示,並且沒有任何eclipse問題。 我不想在任何按鈕的點擊或任何手動事件生成上生成通知,但會按照我指定的日期和時間生成通知。setLatestEventInfo()無法在Android Studio中解析

規範服務類如下:

public class MyRemiderService extends Service { 
private NotificationManager mManager; 

@Override 
public IBinder onBind(Intent intent) { 

    return null; 
} 

@Override 
public void onCreate() { 

    super.onCreate(); 
} 

@Override 
@Deprecated 
public void onStart(Intent intent, int startId) { 
    super.onStart(intent, startId); 
    mManager = (NotificationManager) getApplicationContext() 
      .getSystemService(getApplicationContext().NOTIFICATION_SERVICE); 
    Intent intent1 = new Intent(this.getApplicationContext(), 
      HomeActivity.class); 
    Notification notification = new Notification(R.drawable.notification_template_icon_bg, 
      "This is a test message!", System.currentTimeMillis()); 
    intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP 
      | Intent.FLAG_ACTIVITY_CLEAR_TOP); 
    PendingIntent pendingNotificationIntent = PendingIntent.getActivity(
      this.getApplicationContext(), 0, intent1, 
      PendingIntent.FLAG_UPDATE_CURRENT); 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 
    notification.setLatestEventInfo(this.getApplicationContext(), 
      "AlarmManagerDemo", "This is a test message!", 
      pendingNotificationIntent); 


    mManager.notify(0, notification); 
} 

@Override 
public void onDestroy() { 

    super.onDestroy(); 
} 

請讓我提供有關IT解決方案..謝謝。

+0

哦~~ ..是否有任何替代關於它 ? –

回答

9

正如在這裏看到setLatestEventInfo

setLatestEventInfo方法是從通知類中刪除

要創建Notification使用Notification.Builder類爲:

Notification.Builder builder = new Notification.Builder(MyRemiderService.this); 
..... 
builder.setSmallIcon(R.drawable. notification_template_icon_bg) 
     .setContentTitle("ContentTitle") 
     ..... 
     .setContentIntent(pendingNotificationIntent); 

Notification notification = builder.getNotification(); 
notificationManager.notify(R.drawable.notification_template_icon_bg, notification); 
1
Notification.Builder builder = new Notification.Builder(MainActivity.this); 
Intent notificationIntent = new Intent(this,MainActivity.class); 
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,notificationIntent, 0); 
builder.setSmallIcon(R.drawable. notification_template_icon_bg) 
     .setContentTitle("Music player") 
     .setContentIntent(pendingIntent); 
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
Notification notification = builder.getNotification(); 
notificationManager.notify(R.drawable.notification_template_icon_bg, notification); 
+0

請檢查此爲23+ SDK版本 –

相關問題