首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >android显示通知,在任何应用程序上都有弹出窗口

android显示通知,在任何应用程序上都有弹出窗口
EN

Stack Overflow用户
提问于 2015-04-30 00:29:56
回答 1查看 86.4K关注 0票数 64

使用下面的代码,我的通知仅添加到通知栏,不会显示弹出式消息,就像您在另一个应用程序中收到whatsapp消息一样。是什么让通知发生了这种情况?

代码语言:javascript
复制
private void sendNotification(int distance, ViewObject viewObject) {
    Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notificationIntent.putExtra("path", viewObject.getPath());
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    stackBuilder.addParentStack(MainActivity.class);
    stackBuilder.addNextIntent(notificationIntent);
    PendingIntent notificationPendingIntent = stackBuilder.getPendingIntent(Integer.parseInt(viewObject.getRefId()), PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle();
    bigText.bigText(String.format(getString(R.string.notification), viewObject.getTitle()));
    bigText.setBigContentTitle(getString(R.string.hello));

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.drawable.ic_wald_poi)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_poi))
            .setColor(getResources().getColor(R.color.primary))
            .setContentTitle(getString(R.string.hello))
            .setContentIntent(notificationPendingIntent)
            .setContentText(String.format(getString(R.string.notification), viewObject.getTitle()))
            .setDefaults(Notification.DEFAULT_ALL)
            .setStyle(bigText);

    builder.setAutoCancel(true);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, builder.build());
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29949501

复制
相关文章

相似问题

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