【问题标题】:Android statusbar code deprecatedAndroid 状态条码已弃用
【发布时间】:2013-03-10 01:01:06
【问题描述】:

嗨,伙计们,我正在尝试开发一个需要在特定时间为用户发送通知的应用程序。在互联网上,我找到了这段代码,但 eclipse 说它已被弃用。 您知道使用我的 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);

非常感谢!

【问题讨论】:

    标签: android notifications statusbar


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2012-11-06
      • 2017-02-19
      • 2012-12-25
      • 2021-08-31
      • 2015-09-18
      • 2018-02-11
      • 2018-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多