当我尝试在API级别19
中使用它时,我得到了he constructor Notification(int, CharSequence, long) is deprecated
对于通知我做了如下代码
@Override
public void onReceive(Context context, Intent intent) {
nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "Nithin";
CharSequence message = "Crazy About Android...";
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(), 0);
Notification notif = new Notification(R.drawable.icon,
"Crazy About Android...", System.currentTimeMillis());
notif.setLatestEventInfo(context, from, message, contentIntent);
nm.notify(1, notif);
}
AlarmManager am ;
public void setOneTimeAlarm() {
Intent intent = new Intent(this, TimeAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_ONE_SHOT);
am.set(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + (5 * 1000), pendingIntent);
}
public void setRepeatingAlarm() {
Intent intent = new Intent(this, TimeAlarm.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),
(5 * 1000), pendingIntent);
}
Inside onCreate(Bundle SavedInstanceState){
am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
setOneTimeAlarm();
获取通知错误通知=新通知(R.drawable.icon, “Crazy About Android ...”,System.currentTimeMillis());
The constructor Notification(int, CharSequence, long) is deprecated
为什么会这样?
答案 0 :(得分:2)
您可以使用NotificationBuilder
或support.v4
库
support.v13
这里
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this, ViewMovie_Details.class);
PendingIntent alarmIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(msg)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setAutoCancel(true)
.setContentText("Yuhu New Notification");
mBuilder.setContentIntent(alarmIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
答案 1 :(得分:1)
他们添加了Notification.Builder并希望您使用它。这并不意味着使用旧的方式不会起作用。如果您获得了预期的结果,我可能会忽略这一点,但要了解将来可能有更好的方法来重写您的代码。
答案 2 :(得分:1)
来自文档
公共通知(int图标,CharSequence tickerText,长时间)
在API级别1中添加此构造函数在API级别11中已弃用。 请改用Notification.Builder。
我猜它是一个lint警告你正在使用一个不推荐使用的构造函数。
所以使用Notification.Builder。
http://developer.android.com/reference/android/app/Notification.Builder.html
Exmaple @
http://developer.android.com/guide/topics/ui/notifiers/notifications.html