首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我正在尝试在应用程序上生成通知,但收到错误:无法解析setLatestEventInfo()方法

我正在尝试在应用程序上生成通知,但收到错误:无法解析setLatestEventInfo()方法
EN

Stack Overflow用户
提问于 2016-03-01 17:00:49
回答 1查看 121关注 0票数 0
代码语言:javascript
运行
复制
 private void Notify(String notificationTitle, String notificationMessage){

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

        @SuppressWarnings("deprecation")

        Notification notification = new Notification(R.drawable.logob,"New Message", System.currentTimeMillis());
        Intent notificationIntent = new Intent(this,NotificationView.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

        notification.setLatestEventInfo(foradmin.this, notificationTitle,notificationMessage, pendingIntent);
        notificationManager.notify(9999, notification);
    }

尝试在应用程序上生成通知,但我收到错误,无法解析setLatestEventInfo()方法。

EN

回答 1

Stack Overflow用户

发布于 2016-03-01 17:49:14

试着这样做。it perfectly.Hope this helps.Thanks起作用

代码语言:javascript
运行
复制
 PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 1, intent, 0);

        Notification.Builder builder = new Notification.Builder(MainActivity.this);

        builder.setAutoCancel(false);
        builder.setTicker("this is ticker text");
        builder.setContentTitle("WhatsApp Notification");               
        builder.setContentText("You have a new message");
        builder.setSmallIcon(R.drawable.ic_launcher);
        builder.setContentIntent(pendingIntent);
        builder.setOngoing(true);
        builder.setSubText("This is subtext...");   //API level 16
        builder.setNumber(100);
        builder.build();

        myNotication = builder.getNotification();
        manager.notify(11, myNotication);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35718474

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档