gpt4 book ai didi

安卓服务应用

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:41:52 24 4
gpt4 key购买 nike

我正在为 Android 设备编写一个软件套件,用于跟踪通话时间和其他各种通话信息。我希望其中一个应用程序作为服务运行而无需从 Activity 启动,我希望它在手机启动时立即初始化,并保持持续运行,监听电话,将信息记录到数据库中必要的。该服务需要在每次通话结束时向用户显示一个对话框。

2个问题:

  1. 如何让程序(服务)在启动时自动初始化,无需用户设置或交互?

  2. 我的印象是,如果不使用 Activity,就无法实例化和显示对话框。我希望对话框出现在用户当前屏幕上的任何内容之上,并显示一个对话框。有没有办法让 Activity 对当前 Activity 完全透明,或者有没有办法显示来自服务的对话框?

提前致谢。

最佳答案

How do I get the program (Service) to initialize at boot automatically with no user setting or interaction required?

将此权限添加到您的 list 中:

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

然后将接收器添加到您的 list 中:

<receiver android:name="your.package.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>

在 Java 代码中创建一个接收器:

public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// start the service from here
}
}

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?

是的,这是真的。您必须有一个弹出对话框的 Activity 。要创建透明 Activity ,请在您的 res/values/styles.xml 文件中添加以下样式(如果您没有,请创建它。)这是一个完整的文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#00000000</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>

然后将样式应用到您的 Activity 中,例如:

<activity android:name=".TransparentActivity" android:theme="@style/Theme.Transparent">
...
</activity>

关于安卓服务应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5251547/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com