创建状态栏通知时 Android 应用程序置于最前面

发布于 2025-01-05 16:39:28 字数 379 浏览 1 评论 0原文

基本上我正在遵循以下有关如何创建状态栏通知的教程: http://mobiforge.com/developing/story/displaying-status-bar -notifications-android

(使用类 MainActivity.java AlarmDetail.java DisplayNotification.java 位于页面中间)

我遇到的问题是,当创建通知时,应用程序也会被带到前面;为了防止这种情况发生,我需要做出哪些改变?

提前致谢。

Basically I was following the following tutorial on how to create status bar notification:
http://mobiforge.com/developing/story/displaying-status-bar-notifications-android

(using the classes MainActivity.java alarmDetail.java DisplayNotification.java half way down the page)

The problem I have is that when the notification is created, the application is also brought to the front; what changes would I need to make in order to prevent this happening?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃→可爱长大的 2025-01-12 16:39:29

试试这个:像 showNotification("statusbar title",ID) 一样调用这个方法

NotificationManager mNM;
void showNoitification(String text, int id) {
    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // CharSequence text = "Batch action in progress";
    Notification notification = new Notification(
            android.R.drawable.arrow_up_float, text,
            System.currentTimeMillis());
    notification.defaults = Notification.FLAG_ONLY_ALERT_ONCE
            + Notification.FLAG_AUTO_CANCEL;
    // Intent pendingintent = new Intent(this, BlankActivity.class);
    Intent pendingintent = new Intent();
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            pendingintent, 0);
    notification.setLatestEventInfo(this, "your application", text, contentIntent);
    // notification.deleteIntent;
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    mNM.notify(id, notification);

}

try this: call this method like showNotification("statusbar title",ID)

NotificationManager mNM;
void showNoitification(String text, int id) {
    mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // CharSequence text = "Batch action in progress";
    Notification notification = new Notification(
            android.R.drawable.arrow_up_float, text,
            System.currentTimeMillis());
    notification.defaults = Notification.FLAG_ONLY_ALERT_ONCE
            + Notification.FLAG_AUTO_CANCEL;
    // Intent pendingintent = new Intent(this, BlankActivity.class);
    Intent pendingintent = new Intent();
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            pendingintent, 0);
    notification.setLatestEventInfo(this, "your application", text, contentIntent);
    // notification.deleteIntent;
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    mNM.notify(id, notification);

}
纵性 2025-01-12 16:39:29

创建一个在新线程中运行通知的服务。

Create a service running the notification in a new thread.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文