如何在用户关闭标准 android 闹钟后打开我的应用程序?

How to open my app after the user turns off the standard android alarm clock?

我想知道是否可以在用户停用闹钟后立即打开我的应用程序。我读过有关 AlarmManager 的信息,但直到现在我还没有找到解决此问题的令人满意的解决方案。 是否有人已经在该问题上有过经验? 也许它是通过事件监听器工作的?

非常感谢!

您必须创建自己的闹钟应用才能获得此功能。你不能用其他应用程序来做。因此,如果在其他应用程序(包括股票警报应用程序)中设置了闹钟,您将无法打开您的应用程序。

您可以在应用中的闹钟响起后使用 intent 打开一些 activity。您可以使用下面的代码。

Intent newAppIntent;
PackageManager packageManager = getPackageManager();
newAppIntent = packageManager.getLaunchIntentForPackage("Name of app. you want to launch");
newAppIntent.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(newAppIntent);