Android - 从任何地方启动通知?

发布于 2024-09-10 11:46:18 字数 181 浏览 1 评论 0原文

我现在正在 android 上编码,并且我有一个启动和停止服务的活动。然而,与整个应用程序相关的是一个非 android java 应用程序,它与该应用程序一起在后台运行。我需要这个单独的活动才能启动通知,但我不知道如何执行此操作。我无法在我的活动或服务中创建静态方法,因为那样我将无法获取上下文。有办法做到这一点吗?

谢谢! NS

I'm coding on the android right now, and I have an Activity which starts and stops a Service. However, related to this whole application will be a non-android java application which runs in the background alongside this app. I need this separate activity to be able to launch a notification, but I don't know how to do this. I cannot create a static method in either my Activity or my Service since then I wouldn't be able to get the context. Is there a way to do this?

Thanks!
NS

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

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

发布评论

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

评论(1

灵芸 2024-09-17 11:46:18

...非 android java 应用程序
它在后台运行
这个应用程序

嗯......Android 中没有真正支持“非 Android java 应用程序”。

我需要这个单独的活动
能够启动通知,但我
不知道该怎么做。

如果它是一个Activity,只需使用NotificationManager——Activity是一个Context

如果它是“非 android java 应用程序”,请将其重写为 ActivityService

...a non-android java application
which runs in the background alongside
this app

Ummm...there is no real support in Android for "a non-android java application".

I need this separate activity to be
able to launch a notification, but I
don't know how to do this.

If it is an Activity, just use NotificationManager -- Activity is a Context.

If it is "a non-android java application", rewrite it such that it is an Activity or Service.

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