The concept is to be notified at a specific time. Obviously, I did this until I turned on support for versions below HoneyComb and higher.
I installed the minimum version SDK version 8 and the target SDK 17. Since class coding is much larger, I only show the main area where the problem exists:
int currentapiVersion = android.os.Build.VERSION.SDK_INT; Notification notification; PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, TaskDetails.class), 0); if (currentapiVersion < android.os.Build.VERSION_CODES.HONEYCOMB) { notification = new Notification(icon, text, time); notification.setLatestEventInfo(this, title, text, contentIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; mNM.notify(NOTIFICATION, notification); } else { NotificationCompat.Builder builder = new NotificationCompat.Builder( this); notification = builder.setContentIntent(contentIntent) .setSmallIcon(icon).setTicker(text).setWhen(time) .setAutoCancel(true).setContentTitle(title) .setContentText(text).build(); mNM.notify(NOTIFICATION, notification); }
The problem is
- Some methods and constructors of the Notifications class are deprecated.
- So, an alternative to this, "developer.android.com" suggested using
Notification.Builder . - But the
Notification.Builder class has methods that were included in API level 11 (and thus showed errors in the lines "Call requires API level 11 or more" ). - So, this did not allow me to start the project.
- After more searches, I gave me the decision to use the
NotificationCompat.Builder class.
Finally, I entered the stage where no errors were found, and I launched my project on my Sony Xperia Tipo Dual ST21i2 ...
Tragic ending: I get the following error log:
06-01 06:34:14.199: E/AndroidRuntime(4178): FATAL EXCEPTION: main 06-01 06:34:14.199: E/AndroidRuntime(4178): java.lang.NoClassDefFoundError: android.support.v4.app.NotificationCompat$Builder 06-01 06:34:14.199: E/AndroidRuntime(4178): at com.todotaskmanager.service.NotifyService.showNotification(NotifyService.java:99) 06-01 06:34:14.199: E/AndroidRuntime(4178): at com.todotaskmanager.service.NotifyService.onStartCommand(NotifyService.java:68) 06-01 06:34:14.199: E/AndroidRuntime(4178): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2359) 06-01 06:34:14.199: E/AndroidRuntime(4178): at android.app.ActivityThread.access$1900(ActivityThread.java:123) 06-01 06:34:14.199: E/AndroidRuntime(4178): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210) 06-01 06:34:14.199: E/AndroidRuntime(4178): at android.os.Handler.dispatchMessage(Handler.java:99) 06-01 06:34:14.199: E/AndroidRuntime(4178): at android.os.Looper.loop(Looper.java:137) 06-01 06:34:14.199: E/AndroidRuntime(4178): at android.app.ActivityThread.main(ActivityThread.java:4424) 06-01 06:34:14.199: E/AndroidRuntime(4178): at java.lang.reflect.Method.invokeNative(Native Method) 06-01 06:34:14.199: E/AndroidRuntime(4178): at java.lang.reflect.Method.invoke(Method.java:511) 06-01 06:34:14.199: E/AndroidRuntime(4178): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817) 06-01 06:34:14.199: E/AndroidRuntime(4178): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584) 06-01 06:34:14.199: E/AndroidRuntime(4178): at dalvik.system.NativeStart.main(Native Method)
source share