如何在android上收到广播后弹出并要求用户输入

发布于 2024-09-10 01:59:36 字数 368 浏览 2 评论 0原文

嘿,我是 Android 开发新手,正在尝试制作我的第一个应用程序。

我试图实现的是我在 Handcent SMS 中看到的一个功能:弹出通知。

到目前为止,我的应用程序有一个广播接收器,它使用 Toast 来显示传入的 SMS 消息。

但是,我不想制作一个 Toast 通知,而是制作一个弹出窗口来显示消息,并为用户提供一个输入回复的空间和一个发送按钮。 (也是一个简单地确认消息而不回复的按钮)

我将如何实现这一点? 我可以制作自己的“浮动”活动并使用 startActivityForResult 吗? 由于广播接收器不应该做任何繁重的工作,因此是否必须从服务内部触发?

或者我可以使用NotificationManager之类的东西。

hey, im new to android development and trying to make my first application.

What im trying to implement is a feature i've seen in Handcent SMS: the popup notification.

So far, my application has a broadcast receiver that uses Toast to display an incoming SMS message.

However, instead of a Toast notification, I want to make a pop up window that shows the message and offers users a space to type a reply and a button to send. (also a button to simply acknowledge the message without replying)

how would I accomplish this?
can I make my own 'floating' activity and use startActivityForResult?
would that have to be fired from inside of a service since broadcast receivers arent supposed to do any heavy lifting?

or can i use NotificationManager or something.

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

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

发布评论

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

评论(1

残月升风 2024-09-17 01:59:36

您需要有一个活动(布局+事件等),并且为了“浮动”,您需要将其主题设置为对话框,这可以在您定义活动的清单文件中完成,

类​​似

<activity android:name=".utils.TextEntryActivity"
        android:label="Type in the value" android:theme="@android:style/Theme.Dialog" />

于从 BroadcastReceiver 启动其他活动您可以使用 onReceive 事件传递的 Context

context.startActivityForResult(...)

You need to have an activity (layout+events etc) and in order to be 'floating' you need to set it's theme to dialog, this can be done in the manifest file where you define your activity

Something like

<activity android:name=".utils.TextEntryActivity"
        android:label="Type in the value" android:theme="@android:style/Theme.Dialog" />

For starting other activity from BroadcastReceiver you can use the passed Context of the onReceive event.

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