2015-09-08 18 views
5

Api düzey 10'da bir bildirim yapmaya çalışıyorum ve aşağıda kodum var ancak bir sözdizimi hatası alıyorum setLatestEventInfo çözülemiyor. Ben API düzeyinde sizin derleme SDK sürümü bu sorunu görürsünüz 23+ API ayarlanırsasetLatestEventInfo çözümlenemiyor

public static void sendNotification(Context caller, Class<?> activityToLaunch, String title, String msg, int numberOfEvents, boolean sound, boolean flashLed, boolean vibrate, int iconID) { 
    NotificationManager notifier = (NotificationManager) caller.getSystemService(Context.NOTIFICATION_SERVICE); 

    final Notification notify = new Notification(iconID, "", System.currentTimeMillis()); 

    notify.icon = iconID; 
    notify.tickerText = title; 
    notify.when = System.currentTimeMillis(); 
    notify.number = numberOfEvents; 
    notify.flags |= Notification.FLAG_AUTO_CANCEL; 
    if (sound) notify.defaults |= Notification.DEFAULT_SOUND; 

    if (flashLed) { 
     // add lights 
     notify.flags |= Notification.FLAG_SHOW_LIGHTS; 
     notify.ledARGB = Color.BLUE; 
     notify.ledOnMS = 500; 
     notify.ledOffMS = 500; 
    } 

    if (vibrate) { 
     notify.vibrate = new long[]{100, 200, 300}; 
    } 

    Intent toLaunch = new Intent(caller, activityToLaunch); 
    toLaunch.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); 
    toLaunch.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    PendingIntent intentBack = PendingIntent.getActivity(caller, notify.number, toLaunch, 0); 
    notify.setLatestEventInfo(caller, title, msg, intentBack); 
    notifier.notify(notify.number, notify); 
    notify.number = notify.number + 1; 
} 

cevap

8

ile ilgisi olan bir şey tahmin ediyorum. Bu yöntem M (api 23) 'de uzaklaştırılmıştır.

API 4'e yönelik bildirimler yapmak için Android Support Library numaralı telefona eklenmiş olan NotificationCompat.Builder'u kullanabilirsiniz.

Notification noti = new Notification.Builder(mContext) 
     .setContentTitle("New mail from " + sender.toString()) 
     .setContentText(subject) 
     .setSmallIcon(R.drawable.new_mail) 
     .setLargeIcon(aBitmap) 
     .build(); 

Sen "NotificationCompat" ihtiyaç desteklemek için eğer eski API sürümleri için "Notification.Builder" değiştirebilirsiniz: Android Documentation iyi bir örnek vardır.

+0

Uygulama kitaplığınıza megabayt eklediği için destek kitaplığını kullanmıyorsanız ne olur? – Justin

İlgili konular