Android 服务应用程序
我正在为 Android 设备编写一个软件套件,它将跟踪通话时间和各种其他通话信息。我希望其中一个应用程序作为服务运行,而无需从活动启动,并且我希望它在手机启动时立即初始化,并保持持续运行,监听电话,将信息记录到数据库中必要的。该服务需要在每次调用结束时向用户呈现一个对话框。
2 个问题:
如何让程序(服务)在启动时自动初始化,无需用户设置或交互?
我的印象是,如果不使用活动就无法实例化和显示对话框。我希望对话框显示在用户当前屏幕上的任何内容之上,并显示一个对话框。有没有办法使活动对当前活动完全透明,或者有没有办法从服务显示对话框?
提前致谢。
I'm writing a software suite for Android devices that will keep track of call times and various other call info. I'd like one of the applications to run as a Service without being started from an Activity, and I'd like it to initialize immediately when the phone boots, and stay running constantly, listening for phone calls, logging information to a database as necessary. The Service will need to present a dialog to the user at the end of each call.
2 questions:
How do I get the program (Service) to initialize at boot automatically with no user setting or interaction required?
I was under the impression that you cannot instantiate and display dialogs without using an Activity. I would like the dialogs to appear laid over whatever the user currently has on the screen, and display a dialog. Is there a way to make an Activity completely transparent over the current Activity or is there a way to display dialogs from a Service?
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将此权限添加到您的清单中:
然后将接收器添加到您的清单中:
在 Java 代码中创建接收器:
是的,确实如此。您必须有一个弹出对话框的活动。要创建透明活动,请在
res/values/styles.xml
文件中添加以下样式(如果没有,请创建它。)这是一个完整的文件:然后将该样式应用到您的活动,例如:
Add this permission to your manifest:
Then add a receiver to your manifest:
Create a receiver in Java code:
Yes, that's true. You have to have an activity that pops up the dialog. To create a transparent activity add the following style in your
res/values/styles.xml
file (if you don’t have one, create it.) Here’s a complete file:Then apply the style to your activity, for example: