2013-05-13 9 views
6

मैं मैं कहाँ अधिसूचना का इस्तेमाल किया है प्रदर्शित करने के लिए एक Android आवेदन जब आवेदन

आवेदन सही काम करता है जब मैं पर कोड चलाने शुरू होता है विकसित किया है एंड्रॉयड एमुलेटर जहां के रूप में 4.0.4

के Android संस्करण है जब मैं वास्तविक उपकरण पर समान चलाने का प्रयास है जो यह मेरे त्रुटि logcat में के रूप में

05-13 19:06:45.824: E/AndroidRuntime(15402): FATAL EXCEPTION: main 
05-13 19:06:45.824: E/AndroidRuntime(15402): java.lang.NoSuchMethodError: android.app.Notification$Builder.addAction 
05-13 19:06:45.824: E/AndroidRuntime(15402): at com.example.gpstracker.MainActivity.onCreate(MainActivity.java:54) 
05-13 19:06:45.824: E/AndroidRuntime(15402): at android.app.Activity.performCreate(Activity.java:4470) 
05-13 19:06:45.824: E/AndroidRuntime(15402): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
05-13 19:06:45.824: E/AndroidRuntime(15402): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 
05-13 19:06:45.824: E/AndroidRuntime(15402): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 

कोड है जो मैं कोशिश की है है,

फेंकता
Notification noti = new Notification.Builder(this) 
       .setContentTitle("Driver GPS Tracker Application") 
       .setContentText("9ciphers") 
       .setSmallIcon(R.drawable.ic_launcher).setContentIntent(in) 
       .addAction(R.drawable.ic_launcher, "Start", i) 
       .addAction(R.drawable.ic_launcher, "Stop", in) 
       .addAction(R.drawable.ic_launcher, "Exit", pIntent).build(); 
     NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
     // Hide the notification after its selected 
     noti.flags |= Notification.FLAG_AUTO_CANCEL; 

     notificationManager.notify(0, noti); 
     Toast.makeText(getApplicationContext(), "Application Started", Toast.LENGTH_SHORT).show(); 
     notifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

किसी को भी यहाँ मैं यहाँ कुछ आपकी मदद के लिए

धन्यवाद याद आ रही है इस को हल करने के मेरी मदद कर सकते

उत्तर

15

addAction() एपीआई स्तर 16 को जोड़ा गया है; एंड्रॉइड 4.0.4 एपीआई स्तर 15 चलाता है या तो एंड्रॉइड सपोर्ट पैकेज से NotificationCompat.Builder पर स्विच करें, या पर कॉल करें यदि Build.VERSION.SDK_INT>=Build.VERSION_CODES.JELLY_BEAN

+0

लेकिन अगर मैं 'अधिसूचना कॉम्पैक्ट.बिल्डर' का उपयोग करता हूं तो मुझे अधिसूचना पैनल पर विभिन्न कार्यों की आवश्यकता होती है, यह अधिसूचना पैनल – NetStarter

+1

@ नेटस्टार्टर में कार्रवाई भाग नहीं जोड़ता है: "अधिसूचना पैनल पर किए जाने वाले विभिन्न कार्यों" को तब तक समर्थित नहीं किया गया था जब तक एंड्रॉइड 4.1। – CommonsWare

+1

@ नेटस्टार्टर http://developer.android.com/reference/android/app/Notification.Builder.html। यदि आपका ऐप एपीआई स्तर 4 के रूप में पुराने एंड्रॉइड के संस्करणों का समर्थन करता है, तो आप इसके बजाय अधिसूचना कॉम्पैक्ट.बिल्डर का उपयोग कर सकते हैं, एंड्रॉइड सपोर्ट लाइब्रेरी – Raghunandan

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