gpt4 book ai didi

android - 如何在我的 Android 应用程序中获取 BroadcastReceiver for Action :android. intent.action.MAIN 和 android.intent.category.HOME

转载 作者:太空宇宙 更新时间:2023-11-03 10:29:07 25 4
gpt4 key购买 nike

每个人

当我按下 home 键时,我可以为这个 Intent 获取 BroadcastReceiver 吗:

       Starting activity: Intent { act=android.intent.action.MAIN   cat=   [android.intent.category.HOME] flg=0x10200000 cmp=com.htc.launcher/.Launcher }

我不想考虑 com.htc.luncher,因为对于其他 Android 设备我们会有所不同。

这是我的 BroadcastReceiver 简单类:

 public class HomeBrodcast extends BroadcastReceiver{

@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();


}

}

在 list 中:

  <receiver android:name="xxx.yyy.zzz.sss.HomeBrodcast">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<categary android:name="android.intent.category.HOME"/>
</intent-filter>
</receiver>

在我的 Activity 中注册 BroadcastReceiver :

          mHomeBrodcast=new HomeBrodcast();
IntentFilter mHomeFilter=new IntentFilter("android.intent.action.MAIN");
mHomeFilter.addCategory("android.intent.category.HOME");
registerReceiver(mHomeBrodcast, mHomeFilter);

现在的问题是当启动我的应用程序后我按下 Home 按钮并且我的日志显示这个 Intent 时:

  12-27 14:01:11.230: I/ActivityManager(123): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10200000 cmp=com.htc.launcher/.Launcher }

所以我的目标是为这个 Intent 获取 Receiver 但是当我调试时我没有得到任何东西,有些事情一定是我错了。获取这个 Intent BroadCast 应该是什么问题。

最佳答案

list 中正确的拼写类别应该会有所帮助:)

关于android - 如何在我的 Android 应用程序中获取 BroadcastReceiver for Action :android. intent.action.MAIN 和 android.intent.category.HOME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8642964/

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