2015-09-08 11 views
5

मैं एपीआई स्तर 10 पर एक अधिसूचना करने की कोशिश कर रहा हूं और नीचे मेरा कोड है लेकिन मुझे सिंटैक्स त्रुटि सेट मिल रहा है LatestEventInfo को हल नहीं किया जा सकता है। मैं एपीआई स्तरsetLatestEventInfo को हल नहीं किया जा सकता

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

उत्तर

8

अपने संकलन SDK संस्करण एपीआई 23+ आप इस समस्या को देखेंगे पर सेट है के साथ क्या करना है अपने कुछ अनुमान लगा रहा हूँ। इस विधि को एम (एपीआई 23) में हटा दिया गया था।

एपीआई 4 के लिए अधिसूचनाएं करने के लिए आप NotificationCompat.Builder का उपयोग कर सकते हैं जो Android Support Library में जोड़ा गया था।

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

आप "NotificationCompat" अगर जरूरत का समर्थन करने के पुराने API संस्करण के लिए "Notification.Builder" की जगह ले सकता: Android Documentation एक सभ्य उदाहरण है।

+0

क्या होगा यदि आप समर्थन लाइब्रेरी का उपयोग नहीं कर रहे हैं क्योंकि यह आपके ऐप आकार में मेगाबाइट जोड़ता है? – Justin

संबंधित मुद्दे