Android-- 解决移动魔百盒CM201-2监听不到home键

上篇文章总结了下home键监听的4种方法,链接如下:

Android中监听Home键的4种方法

 

经测试发现,在魔百盒CM201-2上通过广播不能实现home键监听。遂,,记录下当前解决方法:

采用第二种方法可以解决当前尴尬问题,代码如下:

    /**
     * 兼容移动魔百盒CM201-2
     */
    @Override
    protected void onUserLeaveHint() {
        Log.d(TAG,"短按home键...");
        Log.d(TAG,"onUserLeaveHint...");
        super.onUserLeaveHint();
        Intent intent = new Intent(MainActivity.this, BackgroundService.class);
        intent.setAction(STOP_SERVICE);
        startService(intent);
    }

 

但是如果从一个Activity启动一个新的Activity,onUserLeaveHint也会被调用。。。

再次翻阅文档,发现Intent中的一个Flag:
 

public static final int FLAG_ACTIVITY_NO_USER_ACTION

Since: API Level 3
If set, this flag will prevent the normal onUserLeaveHint() callback from occurring on the current frontmost activity before it is paused as the newly-started activity is brought to the front.

Typically, an activity can rely on that callback to indicate that an explicit user action has caused their activity to be moved out of the foreground. 
The callback marks an appropriate point in the activity's lifecycle for it to dismiss any notifications that it intends to display "until the user has seen them," such as a blinking LED.
If an activity is ever started via any non-user-driven events such as phone-call receipt or an alarm handler, this flag should be passed to Context.startActivity, ensuring that the pausing activity does not think the user has acknowledged its notification.


这正是我想要的,这样,在启动activity时,往intent中加上这个flag,onUserLeaveHint就不会再被调用了,hoory...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据提供的引用信息,魔百盒CM201-2 M8273是一款使用海思3798mv300主控芯片的盒子。该固件适用于使用EMMC或NAND闪存的板号为8268、8270、8273的魔百盒CM201-2。你可以在提供的下载地址中获取相关固件并按照固件内的刷机步骤进行操作。请注意,刷机操作涉及风险,请慎重选择,并遵循相关法律法规。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [魔百盒CM201-2-全套通用-免拆机-刷机固件](https://blog.csdn.net/fatiaozhang9527/article/details/122052580)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [新魔百和CM201-2_M8268_M8270_M8273_MV300朝歌代工NAND字库盒子刷机救砖分享经验](https://blog.csdn.net/feimaotuis/article/details/131396864)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [魔百盒CM201-2_朝歌ZG_主板版号M8291_强刷固件包](https://blog.csdn.net/fatiaozhang9527/article/details/125114294)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值