0

Hi mates i'm trying to develop an app which needs to send a notification for the user at certain time. In the internet i found this code but eclipse says that it's deprecated. Do you know which is the proper way to do it with my API? (16)

NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

int icon = R.drawable.worldmap2;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText,when);
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
final Intent intent1 = new Intent(context, HttpExampleLimits.class);
PendingIntent pIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent1, 0);
notification.setLatestEventInfo(context, contentTitle,contentText, pIntent);


nm.notify(1, notification);

Thank you very much!

4

1 回答 1

0

实现它的最好方法是使用支持库和NotificationCompat类。

您可以在官方文档上找到很多示例:http: //developer.android.com/guide/topics/ui/notifiers/notifications.html

于 2013-03-20T18:57:22.373 回答